Ejemplo n.º 1
0
		[ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)] // FindType method call.
		internal MappedFunction(MappedMetaModel model, FunctionMapping map, MethodInfo method)
		{
			this.model = model;
			this.map = map;
			this.method = method;
			this.rowTypes = _emptyTypes;

			if(map.Types.Count == 0 && this.method.ReturnType == typeof(IMultipleResults))
			{
				throw Error.NoResultTypesDeclaredForFunction(method.Name);
			}
			else if(map.Types.Count > 1 && this.method.ReturnType != typeof(IMultipleResults))
			{
				throw Error.TooManyResultTypesDeclaredForFunction(method.Name);
			}
			else if(map.Types.Count == 1 && this.method.ReturnType != typeof(IMultipleResults))
			{
				Type elementType = TypeSystem.GetElementType(method.ReturnType);
				this.rowTypes = new List<MetaType>(1) { this.GetMetaType(map.Types[0], elementType) }.AsReadOnly();
			}
			else if(map.Types.Count > 0)
			{
				List<MetaType> rowTypes = new List<MetaType>();
				foreach(TypeMapping rtm in map.Types)
				{
					Type elementType = model.FindType(rtm.Name);
					if(elementType == null)
					{
						throw Error.CouldNotFindElementTypeInModel(rtm.Name);
					}
					MetaType mt = this.GetMetaType(rtm, elementType);
					// Only add unique meta types
					if(!rowTypes.Contains(mt))
					{
						rowTypes.Add(mt);
					}
				}
				this.rowTypes = rowTypes.AsReadOnly();
			}
			else if(map.FunReturn != null)
			{
				this.returnParameter = new MappedReturnParameter(method.ReturnParameter, map.FunReturn);
			}

			// Parameters.
			ParameterInfo[] pis = this.method.GetParameters();
			if(pis.Length > 0)
			{
				List<MetaParameter> mps = new List<MetaParameter>(pis.Length);
				if(this.map.Parameters.Count != pis.Length)
				{
					throw Error.IncorrectNumberOfParametersMappedForMethod(this.map.MethodName);
				}
				for(int i = 0; i < pis.Length; i++)
				{
					mps.Add(new MappedParameter(pis[i], this.map.Parameters[i]));
				}
				this.parameters = mps.AsReadOnly();
			}
			else
			{
				this.parameters = _emptyParameters;
			}
		}
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="metaType">The parent meta type.</param>
        /// <param name="mi">The method info.</param>
        public AttributedMetaFunction(AttributedMetaModel model, MethodInfo mi) {
            this.model = model;
            this.methodInfo = mi;
            this.rowTypes = _emptyTypes;

            this.functionAttrib = Attribute.GetCustomAttribute(mi, typeof(FunctionAttribute), false) as FunctionAttribute;
            System.Diagnostics.Debug.Assert(functionAttrib != null);

            // Gather up all mapped results
            ResultTypeAttribute[] attrs = (ResultTypeAttribute[])Attribute.GetCustomAttributes(mi, typeof(ResultTypeAttribute));
            if (attrs.Length == 0 && mi.ReturnType == typeof(IMultipleResults)) {
                throw Error.NoResultTypesDeclaredForFunction(mi.Name);
            }
            else if (attrs.Length > 1 && mi.ReturnType != typeof(IMultipleResults)) {
                throw Error.TooManyResultTypesDeclaredForFunction(mi.Name);
            }
            else if (attrs.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);
                this.rowTypes = new List<MetaType>(1) { this.GetMetaType(elementType) }.AsReadOnly();
            }
            else if (attrs.Length > 0) {
                List<MetaType> rowTypes = new List<MetaType>();
                foreach (ResultTypeAttribute rat in attrs) {
                    Type type = rat.Type;
                    MetaType mt = this.GetMetaType(type);
                    // Only add unique meta types
                    if (!rowTypes.Contains(mt)) {
                        rowTypes.Add(mt);
                    } 
                }
                this.rowTypes = rowTypes.AsReadOnly();
            }
            else {
                this.returnParameter = new AttributedMetaParameter(this.methodInfo.ReturnParameter);
            }

            // gather up all meta parameter
            ParameterInfo[] pis = mi.GetParameters();
            if (pis.Length > 0) {
                List<MetaParameter> mps = new List<MetaParameter>(pis.Length);
                for (int i = 0, n = pis.Length; i < n; i++) {
                    AttributedMetaParameter metaParam = new AttributedMetaParameter(pis[i]);
                    mps.Add(metaParam);
                }
                this.parameters = mps.AsReadOnly();
            }
            else {
                this.parameters = _emptyParameters;
            }
        }
Ejemplo n.º 3
0
        [ResourceConsumption(ResourceScope.Assembly | ResourceScope.Machine)]      // FindType method call.
        internal MappedFunction(MappedMetaModel model, FunctionMapping map, MethodInfo method)
        {
            this.model    = model;
            this.map      = map;
            this.method   = method;
            this.rowTypes = _emptyTypes;

            if (map.Types.Count == 0 && this.method.ReturnType == typeof(IMultipleResults))
            {
                throw Error.NoResultTypesDeclaredForFunction(method.Name);
            }
            else if (map.Types.Count > 1 && this.method.ReturnType != typeof(IMultipleResults))
            {
                throw Error.TooManyResultTypesDeclaredForFunction(method.Name);
            }
            else if (map.Types.Count == 1 && this.method.ReturnType != typeof(IMultipleResults))
            {
                Type elementType = TypeSystem.GetElementType(method.ReturnType);
                this.rowTypes = new List <MetaType>(1)
                {
                    this.GetMetaType(map.Types[0], elementType)
                }.AsReadOnly();
            }
            else if (map.Types.Count > 0)
            {
                List <MetaType> rowTypes = new List <MetaType>();
                foreach (TypeMapping rtm in map.Types)
                {
                    Type elementType = model.FindType(rtm.Name);
                    if (elementType == null)
                    {
                        throw Error.CouldNotFindElementTypeInModel(rtm.Name);
                    }
                    MetaType mt = this.GetMetaType(rtm, elementType);
                    // Only add unique meta types
                    if (!rowTypes.Contains(mt))
                    {
                        rowTypes.Add(mt);
                    }
                }
                this.rowTypes = rowTypes.AsReadOnly();
            }
            else if (map.FunReturn != null)
            {
                this.returnParameter = new MappedReturnParameter(method.ReturnParameter, map.FunReturn);
            }

            // Parameters.
            ParameterInfo[] pis = this.method.GetParameters();
            if (pis.Length > 0)
            {
                List <MetaParameter> mps = new List <MetaParameter>(pis.Length);
                if (this.map.Parameters.Count != pis.Length)
                {
                    throw Error.IncorrectNumberOfParametersMappedForMethod(this.map.MethodName);
                }
                for (int i = 0; i < pis.Length; i++)
                {
                    mps.Add(new MappedParameter(pis[i], this.map.Parameters[i]));
                }
                this.parameters = mps.AsReadOnly();
            }
            else
            {
                this.parameters = _emptyParameters;
            }
        }
 private System.Data.ParameterDirection GetParameterDirection(MetaParameter p) {
     if (p.Parameter.IsRetval) {
         return System.Data.ParameterDirection.ReturnValue;
     }
     else if (p.Parameter.IsOut) {
         return System.Data.ParameterDirection.Output;
     }
     else if (p.Parameter.ParameterType.IsByRef) {
         return System.Data.ParameterDirection.InputOutput;
     }
     else {
         return System.Data.ParameterDirection.Input;
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="metaType">The parent meta type.</param>
        /// <param name="mi">The method info.</param>
        public AttributedMetaFunction(AttributedMetaModel model, MethodInfo mi)
        {
            this.model      = model;
            this.methodInfo = mi;
            this.rowTypes   = _emptyTypes;

            this.functionAttrib = Attribute.GetCustomAttribute(mi, typeof(FunctionAttribute), false) as FunctionAttribute;
            System.Diagnostics.Debug.Assert(functionAttrib != null);

            // Gather up all mapped results
            ResultTypeAttribute[] attrs = (ResultTypeAttribute[])Attribute.GetCustomAttributes(mi, typeof(ResultTypeAttribute));
            if (attrs.Length == 0 && mi.ReturnType == typeof(IMultipleResults))
            {
                throw Error.NoResultTypesDeclaredForFunction(mi.Name);
            }
            else if (attrs.Length > 1 && mi.ReturnType != typeof(IMultipleResults))
            {
                throw Error.TooManyResultTypesDeclaredForFunction(mi.Name);
            }
            else if (attrs.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);
                this.rowTypes = new List <MetaType>(1)
                {
                    this.GetMetaType(elementType)
                }.AsReadOnly();
            }
            else if (attrs.Length > 0)
            {
                List <MetaType> rowTypes = new List <MetaType>();
                foreach (ResultTypeAttribute rat in attrs)
                {
                    Type     type = rat.Type;
                    MetaType mt   = this.GetMetaType(type);
                    // Only add unique meta types
                    if (!rowTypes.Contains(mt))
                    {
                        rowTypes.Add(mt);
                    }
                }
                this.rowTypes = rowTypes.AsReadOnly();
            }
            else
            {
                this.returnParameter = new AttributedMetaParameter(this.methodInfo.ReturnParameter);
            }

            // gather up all meta parameter
            ParameterInfo[] pis = mi.GetParameters();
            if (pis.Length > 0)
            {
                List <MetaParameter> mps = new List <MetaParameter>(pis.Length);
                for (int i = 0, n = pis.Length; i < n; i++)
                {
                    AttributedMetaParameter metaParam = new AttributedMetaParameter(pis[i]);
                    mps.Add(metaParam);
                }
                this.parameters = mps.AsReadOnly();
            }
            else
            {
                this.parameters = _emptyParameters;
            }
        }
		private Data.ParameterDirection GetParameterDirection(MetaParameter p)
		{
			if(p.Parameter.IsRetval)
			{
				return Data.ParameterDirection.ReturnValue;
			}
			if(p.Parameter.IsOut)
			{
				return Data.ParameterDirection.Output;
			}
			if(p.Parameter.ParameterType.IsByRef)
			{
				return Data.ParameterDirection.InputOutput;
			}
			return Data.ParameterDirection.Input;
		}