private void InitDataMembers() { if (dataMembers == null) { dataMemberMap = new Dictionary <MetaPosition, MetaDataMember>(); var ordinal = 0; const BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; var fields = TypeSystem.GetAllFields(type, flags).ToArray(); for (int i = 0, n = fields.Length; i < n; i++) { var fi = fields[i]; var dataMember = new AttributedMetaDataMember(this, fi, ordinal); ValidatePrimaryKeyMember(dataMember); // must be public or persistent if (dataMember.IsPersistent || fi.IsPublic) { dataMemberMap.Add(new MetaPosition(fi), dataMember); ordinal++; // must be persistent for the rest if (dataMember.IsPersistent) { InitSpecialMember(dataMember); } } } var properties = TypeSystem.GetAllProperties(type, flags).ToArray(); for (int i = 0, n = properties.Length; i < n; i++) { var property = properties[i]; var dataMember = new AttributedMetaDataMember(this, property, ordinal); ValidatePrimaryKeyMember(dataMember); // must be public or persistent var isPublic = (property.CanRead && property.GetGetMethod(false) != null) && (!property.CanWrite || property.GetSetMethod(false) != null); if (dataMember.IsPersistent || isPublic) { dataMemberMap.Add(new MetaPosition(property), dataMember); ordinal++; // must be persistent for the rest if (dataMember.IsPersistent) { InitSpecialMember(dataMember); } } } dataMembers = new List <MetaDataMember>(dataMemberMap.Values).AsReadOnly(); } }
private void InitDataMembers() { if (this.dataMembers == null) { this.dataMemberMap = new Dictionary <MetaPosition, MetaDataMember>(); int ordinal = 0; BindingFlags flags = BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; FieldInfo[] infoArray = TypeSystem.GetAllFields(this.type, flags).ToArray <FieldInfo>(); if (infoArray != null) { int index = 0; int length = infoArray.Length; while (index < length) { FieldInfo mi = infoArray[index]; MetaDataMember mm = new AttributedMetaDataMember(this, mi, ordinal); this.ValidatePrimaryKeyMember(mm); if (mm.IsPersistent || mi.IsPublic) { this.dataMemberMap.Add(new MetaPosition(mi), mm); ordinal++; if (mm.IsPersistent) { this.InitSpecialMember(mm); } } index++; } } PropertyInfo[] infoArray2 = TypeSystem.GetAllProperties(this.type, flags).ToArray <PropertyInfo>(); if (infoArray2 != null) { int num4 = 0; int num5 = infoArray2.Length; while (num4 < num5) { PropertyInfo info2 = infoArray2[num4]; MetaDataMember member2 = new AttributedMetaDataMember(this, info2, ordinal); this.ValidatePrimaryKeyMember(member2); bool flag = (info2.CanRead && (info2.GetGetMethod(false) != null)) && (!info2.CanWrite || (info2.GetSetMethod(false) != null)); if (member2.IsPersistent || flag) { this.dataMemberMap.Add(new MetaPosition(info2), member2); ordinal++; if (member2.IsPersistent) { this.InitSpecialMember(member2); } } num4++; } } this.dataMembers = new List <MetaDataMember>(this.dataMemberMap.Values).AsReadOnly(); } }
private void InitDataMembers() { if(this.dataMembers == null) { this.dataMemberMap = new Dictionary<MetaPosition, MetaDataMember>(); int ordinal = 0; BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; FieldInfo[] fis = TypeSystem.GetAllFields(this.type, flags).ToArray(); if(fis != null) { for(int i = 0, n = fis.Length; i < n; i++) { FieldInfo fi = fis[i]; MetaDataMember mm = new AttributedMetaDataMember(this, fi, ordinal); ValidatePrimaryKeyMember(mm); // must be public or persistent if(!mm.IsPersistent && !fi.IsPublic) continue; this.dataMemberMap.Add(new MetaPosition(fi), mm); ordinal++; // must be persistent for the rest if(!mm.IsPersistent) continue; this.InitSpecialMember(mm); } } PropertyInfo[] pis = TypeSystem.GetAllProperties(this.type, flags).ToArray(); if(pis != null) { for(int i = 0, n = pis.Length; i < n; i++) { PropertyInfo pi = pis[i]; MetaDataMember mm = new AttributedMetaDataMember(this, pi, ordinal); ValidatePrimaryKeyMember(mm); // must be public or persistent bool isPublic = (pi.CanRead && pi.GetGetMethod(false) != null) && (!pi.CanWrite || pi.GetSetMethod(false) != null); if(!mm.IsPersistent && !isPublic) continue; this.dataMemberMap.Add(new MetaPosition(pi), mm); ordinal++; // must be persistent for the rest if(!mm.IsPersistent) continue; this.InitSpecialMember(mm); } } this.dataMembers = new List<MetaDataMember>(this.dataMemberMap.Values).AsReadOnly(); } }
private void InitDataMembers() { if (this.dataMembers == null) { Dictionary <object, MetaDataMember> map = new Dictionary <object, MetaDataMember>(); List <MetaDataMember> dMembers = new List <MetaDataMember>(); int ordinal = 0; BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; // Map of valid mapped names. Dictionary <string, MemberMapping> names = new Dictionary <string, MemberMapping>(); Type currentType = this.type; for (TypeMapping tm = this.typeMapping; tm != null; tm = tm.BaseType) { foreach (MemberMapping mmap in tm.Members) { names[mmap.MemberName + ":" + currentType.Name] = mmap; } currentType = currentType.BaseType; } HashSet <string> namesSeen = new HashSet <string>(); // Keep track of which names from the mapping file have been seen. FieldInfo[] fis = TypeSystem.GetAllFields(this.type, flags).ToArray(); if (fis != null) { foreach (FieldInfo fi in fis) { MemberMapping mmap; string name = fi.Name + ":" + fi.DeclaringType.Name; if (names.TryGetValue(name, out mmap)) { namesSeen.Add(name); object dn = InheritanceRules.DistinguishedMemberName(fi); MetaDataMember mm; if (!map.TryGetValue(dn, out mm)) { mm = new MappedDataMember(this, fi, mmap, ordinal); map.Add(InheritanceRules.DistinguishedMemberName(mm.Member), mm); dMembers.Add(mm); this.InitSpecialMember(mm); } ValidatePrimaryKeyMember(mm); ordinal++; } } } PropertyInfo[] pis = TypeSystem.GetAllProperties(this.type, flags).ToArray(); if (pis != null) { foreach (PropertyInfo pi in pis) { MemberMapping mmap; string name = pi.Name + ":" + pi.DeclaringType.Name; if (names.TryGetValue(name, out mmap)) { namesSeen.Add(name); MetaDataMember mm; object dn = InheritanceRules.DistinguishedMemberName(pi); if (!map.TryGetValue(dn, out mm)) { mm = new MappedDataMember(this, pi, mmap, ordinal); map.Add(InheritanceRules.DistinguishedMemberName(mm.Member), mm); dMembers.Add(mm); this.InitSpecialMember(mm); } ValidatePrimaryKeyMember(mm); ordinal++; } } } this.dataMembers = dMembers.AsReadOnly(); this.dataMemberMap = map; // Finally, make sure that all types in the mapping file were consumed. foreach (string name in namesSeen) { names.Remove(name); } foreach (var orphan in names) { Type aboveRoot = inheritanceRoot.Type.BaseType; while (aboveRoot != null) { foreach (MemberInfo mi in aboveRoot.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) { if (String.Compare(mi.Name, orphan.Value.MemberName, StringComparison.Ordinal) == 0) { throw Error.MappedMemberHadNoCorrespondingMemberInType(orphan.Value.MemberName, type.Name); } } aboveRoot = aboveRoot.BaseType; } } } }
private void InitDataMembers() { if (dataMembers == null) { var dictionary = new Dictionary <object, MetaDataMember>(); var list = new List <MetaDataMember>(); int ordinal = 0; const BindingFlags flags = BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance; var dictionary2 = new Dictionary <string, MemberMapping>(); Type baseType = type; for (TypeMapping mapping = this.typeMapping; mapping != null; mapping = mapping.BaseType) { foreach (MemberMapping mapping2 in mapping.Members) { dictionary2[mapping2.MemberName + ":" + baseType.Name] = mapping2; } baseType = baseType.BaseType; } var set = new HashSet <string>(); FieldInfo[] infoArray = TypeSystem.GetAllFields(this.type, flags).ToArray <FieldInfo>(); if (infoArray != null) { foreach (FieldInfo info in infoArray) { MemberMapping mapping3; string key = info.Name + ":" + info.DeclaringType.Name; if (dictionary2.TryGetValue(key, out mapping3)) { MetaDataMember member; set.Add(key); object obj2 = InheritanceRules.DistinguishedMemberName(info); if (!dictionary.TryGetValue(obj2, out member)) { member = new MappedDataMember(this, info, mapping3, ordinal); dictionary.Add(InheritanceRules.DistinguishedMemberName(member.Member), member); list.Add(member); this.InitSpecialMember(member); } this.ValidatePrimaryKeyMember(member); ordinal++; } } } PropertyInfo[] infoArray2 = TypeSystem.GetAllProperties(this.type, flags).ToArray <PropertyInfo>(); if (infoArray2 != null) { foreach (PropertyInfo info2 in infoArray2) { MemberMapping mapping4; string str2 = info2.Name + ":" + info2.DeclaringType.Name; if (dictionary2.TryGetValue(str2, out mapping4)) { MetaDataMember member2; set.Add(str2); object obj3 = InheritanceRules.DistinguishedMemberName(info2); if (!dictionary.TryGetValue(obj3, out member2)) { member2 = new MappedDataMember(this, info2, mapping4, ordinal); dictionary.Add(InheritanceRules.DistinguishedMemberName(member2.Member), member2); list.Add(member2); this.InitSpecialMember(member2); } this.ValidatePrimaryKeyMember(member2); ordinal++; } } } this.dataMembers = list.AsReadOnly(); this.dataMemberMap = dictionary; foreach (string str3 in set) { dictionary2.Remove(str3); } foreach (KeyValuePair <string, MemberMapping> pair in dictionary2) { for (Type type2 = this.inheritanceRoot.Type.BaseType; type2 != null; type2 = type2.BaseType) { foreach (MemberInfo info3 in type2.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance)) { if (string.Compare(info3.Name, pair.Value.MemberName, StringComparison.Ordinal) == 0) { throw Error.MappedMemberHadNoCorrespondingMemberInType(pair.Value.MemberName, this.type.Name); } } } } } }