예제 #1
0
 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();
     }
 }
예제 #2
0
        // Methods
        internal AttributedMetaAssociation(AttributedMetaDataMember member, AssociationAttribute attr)
        {
            this.attributeProvider = member.MetaModel.AttributeProvider;

            this.thisMember = member;
            this.isMany     = TypeSystem.IsSequenceType(thisMember.Type);
            Type type = this.isMany ? TypeSystem.GetElementType(thisMember.Type) : thisMember.Type;

            this.otherType            = this.thisMember.DeclaringType.Model.GetMetaType(type);
            this.thisKey              = (attr.ThisKey != null) ? MakeKeys(thisMember.DeclaringType, attr.ThisKey) : thisMember.DeclaringType.IdentityMembers;
            this.otherKey             = (attr.OtherKey != null) ? MakeKeys(otherType, attr.OtherKey) : this.otherType.IdentityMembers;
            this.thisKeyIsPrimaryKey  = AreEqual(this.thisKey, thisMember.DeclaringType.IdentityMembers);
            this.otherKeyIsPrimaryKey = AreEqual(this.otherKey, otherType.IdentityMembers);
            this.isForeignKey         = attr.IsForeignKey;
            this.isUnique             = attr.IsUnique;
            this.deleteRule           = attr.DeleteRule;
            this.deleteOnNull         = attr.DeleteOnNull;
            foreach (MetaDataMember member2 in this.thisKey)
            {
                if (!member2.CanBeNull)
                {
                    this.isNullable = false;
                    break;
                }
            }
            if (this.deleteOnNull && ((!this.isForeignKey || this.isMany) || this.isNullable))
            {
                throw Mapping.Error.InvalidDeleteOnNullSpecification(member);
            }
            if (((this.thisKey.Count != this.otherKey.Count) && (this.thisKey.Count > 0)) && (this.otherKey.Count > 0))
            {
                throw Mapping.Error.MismatchedThisKeyOtherKey(member.Name, member.DeclaringType.Name);
            }
            foreach (MetaDataMember member3 in this.otherType.PersistentDataMembers)
            {
                /* var customAttribute = (AssociationAttribute)Attribute.GetCustomAttribute(member3.Member, typeof(AssociationAttribute)); */
                var customAttribute = this.attributeProvider.GetAssociationAttribute(member3.Member);

                if (((customAttribute != null) && (member3 != this.thisMember)) && (customAttribute.Name == attr.Name))
                {
                    this.otherMember = member3;
                    break;
                }
            }
        }
예제 #3
0
        internal DynamicMetaType(DynamicModel model, MetaType source)
        {
            this.source                      = source;
            this.model                       = model;
            this.extendDataMembers           = new Dictionary <string, MetaDataMember>();
            this.extendPersistentDataMembers = new Dictionary <string, MetaDataMember>();

            dataMemberList = new MyList(source.DataMembers, extendDataMembers);
            var mylist2 = new MyList(source.PersistentDataMembers, extendPersistentDataMembers);

            this.dataMembers           = new ReadOnlyCollection <MetaDataMember>(dataMemberList);
            this.persistentDataMembers = new ReadOnlyCollection <MetaDataMember>(mylist2);
            if (model.Source is AttributedMetaModel)
            {
                if (((AttributedMetaModel)model.Source).AttributeProvider is FluentMappingSource.AttributeProvider)
                {
                    var attrProvider =
                        ((FluentMappingSource.AttributeProvider)((AttributedMetaModel)model.Source).AttributeProvider);

                    var entityMapping = attrProvider.Mapping.GetEntityMapping(source.Type);
                    if (entityMapping != null)
                    {
                        foreach (var item in entityMapping.MemberColumnPairs)
                        {
                            if (item.Key is IndexerMemberInfo)
                            {
                                var dataMember = new AttributedMetaDataMember((AttributedMetaType)this.Source, item.Key, dataMembers.Count);
                                extendDataMembers[item.Key.Name]           = dataMember;
                                extendPersistentDataMembers[item.Key.Name] = dataMember;
                            }
                        }
                    }
                }
            }

            this.identities = dataMembers.Where(m => m.IsPrimaryKey).ToList().AsReadOnly();
        }