private AttributedMetaType CreateInheritedType(Type root, Type type) { MetaType type2; if (!this.types.TryGetValue(type, out type2)) { Debug.Assert(model != null); type2 = new AttributedMetaType(this.model, this.Table, type, this); this.types.Add(type, type2); if ((type != root) && (type.BaseType != typeof(object))) { this.CreateInheritedType(root, type.BaseType); } } return((AttributedMetaType)type2); }
// Methods internal AttributedMetaDataMember(AttributedMetaType metaType, MemberInfo mi, int ordinal) { this.declaringType = mi.DeclaringType; this.metaType = metaType; this.member = mi; this.ordinal = ordinal; this.type = TypeSystem.GetMemberType(mi); this.isNullableType = TypeSystem.IsNullableType(this.type); this.attributeProvider = this.MetaModel.AttributeProvider; /* * this.attrColumn = (ColumnAttribute)Attribute.GetCustomAttribute(mi, typeof(ColumnAttribute)); * this.attrAssoc = (AssociationAttribute)Attribute.GetCustomAttribute(mi, typeof(AssociationAttribute)); */ this.attrColumn = attributeProvider.GetColumnAttribute(mi); this.attrAssoc = attributeProvider.GetAssociationAttribute(mi); this.attr = (this.attrColumn != null) ? ((DataAttribute)attrColumn) : this.attrAssoc; if (attr != null && attr.Storage != null) { MemberInfo[] member = mi.DeclaringType.GetMember(this.attr.Storage, BindingFlags.NonPublic | BindingFlags.Instance); if (member == null || member.Length != 1) { throw Mapping.Error.BadStorageProperty(this.attr.Storage, mi.DeclaringType, mi.Name); } this.storageMember = member[0]; } Type entityType = (this.storageMember != null) ? TypeSystem.GetMemberType(this.storageMember) : this.type; this.isDeferred = this.IsDeferredType(entityType); if ((this.attrColumn != null && this.attrColumn.IsDbGenerated) && (this.attrColumn.IsPrimaryKey && this.attrColumn.AutoSync != AutoSync.Default) && (this.attrColumn.AutoSync != AutoSync.OnInsert)) { throw Mapping.Error.IncorrectAutoSyncSpecification(mi.Name); } }
// Methods internal AttributedRootType(AttributedMetaModel model, AttributedMetaTable table, Type type) : base(model, table, type, null) { this.model = model; var customAttributes = model.AttributeProvider.GetInheritanceMappingAttribute(type); //(InheritanceMappingAttribute[])type.GetCustomAttributes(typeof(InheritanceMappingAttribute), true); if (customAttributes != null && customAttributes.Length > 0) { if (this.Discriminator == null) { throw Mapping.Error.NoDiscriminatorFound(type); } if (!MappingSystem.IsSupportedDiscriminatorType(this.Discriminator.Type)) { throw Mapping.Error.DiscriminatorClrTypeNotSupported(this.Discriminator.DeclaringType.Name, this.Discriminator.Name, this.Discriminator.Type); } this.types = new Dictionary <Type, MetaType>(); this.types.Add(type, this); this.codeMap = new Dictionary <object, MetaType>(); foreach (InheritanceMappingAttribute attribute in customAttributes) { if (!type.IsAssignableFrom(attribute.Type)) { throw Mapping.Error.InheritanceTypeDoesNotDeriveFromRoot(attribute.Type, type); } if (attribute.Type.IsAbstract) { throw Mapping.Error.AbstractClassAssignInheritanceDiscriminator(attribute.Type); } AttributedMetaType type2 = this.CreateInheritedType(type, attribute.Type); if (attribute.Code == null) { throw Mapping.Error.InheritanceCodeMayNotBeNull(); } if (type2.inheritanceCode != null) { throw Mapping.Error.InheritanceTypeHasMultipleDiscriminators(attribute.Type); } object objB = DBConvert.ChangeType(attribute.Code, this.Discriminator.Type); foreach (object obj3 in this.codeMap.Keys) { if ((((objB.GetType() == typeof(string)) && (((string)objB).Trim().Length == 0)) && ((obj3.GetType() == typeof(string)) && (((string)obj3).Trim().Length == 0))) || object.Equals(obj3, objB)) { throw Mapping.Error.InheritanceCodeUsedForMultipleTypes(objB); } } type2.inheritanceCode = objB; this.codeMap.Add(objB, type2); if (attribute.IsDefault) { if (this.inheritanceDefault != null) { throw Mapping.Error.InheritanceTypeHasMultipleDefaults(type); } this.inheritanceDefault = type2; } } if (this.inheritanceDefault == null) { throw Mapping.Error.InheritanceHierarchyDoesNotDefineDefault(type); } } if (this.types != null) { this.inheritanceTypes = this.types.Values.ToList <MetaType>().AsReadOnly(); } else { this.inheritanceTypes = new MetaType[] { this }.ToList <MetaType>().AsReadOnly(); } this.Validate(); }