Ejemplo n.º 1
0
 // Methods
 internal MappedFunction(MappedMetaModel model, FunctionMapping map, MethodInfo method)
 {
     this.model  = model;
     this.map    = map;
     this.method = method;
     rowTypes    = _emptyTypes;
     if ((map.Types.Count == 0) && (this.method.ReturnType == typeof(IMultipleResults)))
     {
         throw Error.NoResultTypesDeclaredForFunction(method.Name);
     }
     if ((map.Types.Count > 1) && (this.method.ReturnType != typeof(IMultipleResults)))
     {
         throw Error.TooManyResultTypesDeclaredForFunction(method.Name);
     }
     if ((map.Types.Count == 1) && (this.method.ReturnType != typeof(IMultipleResults)))
     {
         Type elementType = TypeSystem.GetElementType(method.ReturnType);
         var  list        = new List <MetaType>(1)
         {
             GetMetaType(map.Types[0], elementType)
         };
         rowTypes = list.AsReadOnly();
     }
     else if (map.Types.Count > 0)
     {
         var list2 = new List <MetaType>();
         foreach (TypeMapping mapping in map.Types)
         {
             Type type2 = model.FindType(mapping.Name);
             if (type2 == null)
             {
                 throw Error.CouldNotFindElementTypeInModel(mapping.Name);
             }
             MetaType metaType = this.GetMetaType(mapping, type2);
             if (!list2.Contains(metaType))
             {
                 list2.Add(metaType);
             }
         }
         this.rowTypes = list2.AsReadOnly();
     }
     else if (map.FunReturn != null)
     {
         this.returnParameter = new MappedReturnParameter(method.ReturnParameter, map.FunReturn);
     }
     ParameterInfo[] parameters = this.method.GetParameters();
     if (parameters.Length > 0)
     {
         var list3 = new List <MetaParameter>(parameters.Length);
         if (this.map.Parameters.Count != parameters.Length)
         {
             throw Error.IncorrectNumberOfParametersMappedForMethod(this.map.MethodName);
         }
         for (int i = 0; i < parameters.Length; i++)
         {
             list3.Add(new MappedParameter(parameters[i], this.map.Parameters[i]));
         }
         this.parameters = list3.AsReadOnly();
     }
     else
     {
         this.parameters = _emptyParameters;
     }
 }
Ejemplo n.º 2
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;
            }
        }