Beispiel #1
0
        protected override MetaModel CreateModel(Type dataContextType)
        {
            if (dataContextType == null)
            {
                throw ALinq.Error.ArgumentNull("dataContextType");
            }

            DataContextMapping mapping = getMapping(dataContextType);

            //var type = dataContextType;
            //Debug.Assert(type != null);

            //while (mapping == null && type != typeof(DataContext).BaseType && type != null)
            //{
            //    contextMappings.TryGetValue(type, out mapping);
            //    type = type.BaseType;
            //}


            if (mapping == null)
            {
                throw Error.CouldNotFindMappingForDataContextType(dataContextType);
            }

            var attributeProvider = new AttributeProvider(mapping);
            var model             = new AttributedMetaModel(this, dataContextType, attributeProvider);

            return(model);
        }
Beispiel #2
0
 // Methods
 internal AttributedMetaTable(AttributedMetaModel model, TableAttribute attr, Type rowType)
 {
     Debug.Assert(attr != null);
     this.model     = model;
     this.tableName = string.IsNullOrEmpty(attr.Name) ? rowType.Name : attr.Name;
     this.rowType   = new AttributedRootType(model, this, rowType);
 }
        protected override MetaModel CreateModel(Type dataContextType)
        {
            if (dataContextType == null)
            {
                throw ALinq.Error.ArgumentNull("dataContextType");
            }
            var model = new AttributedMetaModel(this, dataContextType, new AttributeProvider());

            return(model);
        }
Beispiel #4
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();
        }
Beispiel #5
0
        // Methods
        public AttributedMetaFunction(AttributedMetaModel model, MethodInfo mi, IAttributeProvider attributeProvider)
        {
            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }

            if (mi == null)
            {
                throw Error.ArgumentNull("mi");
            }

            if (attributeProvider == null)
            {
                throw Error.ArgumentNull("attributeProvider");
            }

            this.attributeProvider = attributeProvider;

            this.model      = model;
            this.methodInfo = mi;
            this.rowTypes   = _emptyTypes;
            //this.functionAttrib = Attribute.GetCustomAttribute(mi, typeof(FunctionAttribute), false) as FunctionAttribute;
            this.functionAttrib = this.attributeProvider.GetFunction(mi);


            //(ResultTypeAttribute[])Attribute.GetCustomAttributes(mi, typeof(ResultTypeAttribute));
            var resultTypeAttributes = attributeProvider.GetResultTypeAttributes(mi);

            if (resultTypeAttributes != null && resultTypeAttributes.Length == 0 && mi.ReturnType == typeof(IMultipleResults))
            {
                throw Mapping.Error.NoResultTypesDeclaredForFunction(mi.Name);
            }
            if (resultTypeAttributes != null && resultTypeAttributes.Length > 1 && mi.ReturnType != typeof(IMultipleResults))
            {
                throw Mapping.Error.TooManyResultTypesDeclaredForFunction(mi.Name);
            }
            if (((resultTypeAttributes != null && resultTypeAttributes.Length <= 1) && mi.ReturnType.IsGenericType) &&
                (((mi.ReturnType.GetGenericTypeDefinition() == typeof(IEnumerable <>)) ||
                  (mi.ReturnType.GetGenericTypeDefinition() == typeof(ISingleResult <>))) ||
                 (mi.ReturnType.GetGenericTypeDefinition() == typeof(IQueryable <>))))
            {
                Type elementType = TypeSystem.GetElementType(mi.ReturnType);
                var  list        = new List <MetaType>(1);
                list.Add(this.GetMetaType(elementType));
                this.rowTypes = list.AsReadOnly();
            }
            else if (resultTypeAttributes != null && resultTypeAttributes.Length > 0)
            {
                var list2 = new List <MetaType>();
                foreach (ResultTypeAttribute attribute in resultTypeAttributes)
                {
                    Type     type     = attribute.Type;
                    MetaType metaType = this.GetMetaType(type);
                    if (!list2.Contains(metaType))
                    {
                        list2.Add(metaType);
                    }
                }
                this.rowTypes = list2.AsReadOnly();
            }
            else
            {
                this.returnParameter = new AttributedMetaParameter(this.methodInfo.ReturnParameter);
            }
            ParameterInfo[] parameters = mi.GetParameters();
            if (parameters.Length > 0)
            {
                var list3  = new List <MetaParameter>(parameters.Length);
                int index  = 0;
                int length = parameters.Length;
                while (index < length)
                {
                    var item = new AttributedMetaParameter(parameters[index]);
                    list3.Add(item);
                    index++;
                }
                this.parameters = list3.AsReadOnly();
            }
            else
            {
                this.parameters = _emptyParameters;
            }
        }