示例#1
0
        internal MetaTable GetTableNoLocks(Type rowType)
        {
            MetaTable table;

            if (!metaTables.TryGetValue(rowType, out table))
            {
                Type key = GetRoot(rowType) ?? rowType;

                /*
                 * var customAttributes = (TableAttribute[])key.GetCustomAttributes(typeof(TableAttribute), true);
                 * if (customAttributes.Length == 0)
                 * {
                 *  metaTables.Add(rowType, null);
                 *  return table;
                 * }
                 */
                var tableAttribute = AttributeProvider.GetTableAttribute(key);
                if (tableAttribute == null)
                {
                    metaTables.Add(rowType, null);
                    return(table);
                }

                if (!metaTables.TryGetValue(key, out table))
                {
                    /* table = new AttributedMetaTable(this, customAttributes[0], key); */
                    table = new AttributedMetaTable(this, tableAttribute, key);

                    foreach (MetaType type2 in table.RowType.InheritanceTypes)
                    {
                        metaTables.Add(type2.Type, table);
                    }
                }
                if (table.RowType.GetInheritanceType(rowType) == null)
                {
                    metaTables.Add(rowType, null);
                    return(null);
                }
            }
            return(table);
        }
示例#2
0
        // 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();
        }