示例#1
0
 // Methods
 internal MappedAssociation(MappedDataMember mm, AssociationMapping assocMap)
 {
     this.thisMember = mm;
     this.assocMap   = assocMap;
     this.Init();
     this.InitOther();
     if (((this.thisKey.Count != this.otherKey.Count) && (this.thisKey.Count > 0)) && (this.otherKey.Count > 0))
     {
         throw Error.MismatchedThisKeyOtherKey(this.thisMember.Name, this.thisMember.DeclaringType.Name);
     }
 }
示例#2
0
 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);
                     }
                 }
             }
         }
     }
 }