Ejemplo n.º 1
0
        private static Tuple<ParameterInfo[], Expression[]> GetParametersAndArguments(object arguments)
        {
            Expression[] argumentExpressions;
            FickleParameterInfo[] parameterInfos;

            if (arguments == null)
            {
                parameterInfos = new FickleParameterInfo[0];

                argumentExpressions = new Expression[0];
            }
            else if (arguments.GetType().IsAnonymousType())
            {
                var properties = arguments.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                var i = 0;
                argumentExpressions = new Expression[properties.Length];
                parameterInfos = new FickleParameterInfo[properties.Length];

                foreach (var propertyInfo in properties)
                {
                    Type parameterType;
                    var parameterName = propertyInfo.Name;
                    var value = propertyInfo.GetValue(arguments);

                    if (value is Expression)
                    {
                        parameterType = ((Expression)value).Type;
                        argumentExpressions[i] = (Expression)value;
                    }
                    else
                    {
                        parameterType = propertyInfo.PropertyType;
                        argumentExpressions[i] = Expression.Constant(value);
                    }

                    parameterInfos[i] = new FickleParameterInfo(parameterType, parameterName);

                    i++;
                }
            }
            else if (arguments is Expression)
            {
                parameterInfos = new FickleParameterInfo[]
                {
                    new FickleParameterInfo(((Expression)arguments).Type, "arg1")
                };

                argumentExpressions = new Expression[]
                {
                    (Expression)arguments
                };
            }
            else
            {
                parameterInfos = new FickleParameterInfo[]
                {
                    new FickleParameterInfo(arguments.GetType(), "arg1")
                };

                argumentExpressions = new Expression[]
                {
                    Expression.Constant(arguments)
                };
            }

            return new Tuple<ParameterInfo[], Expression[]>(parameterInfos, argumentExpressions);
        }
Ejemplo n.º 2
0
        private static Tuple <ParameterInfo[], Expression[]> GetParametersAndArguments(object arguments)
        {
            Expression[]          argumentExpressions;
            FickleParameterInfo[] parameterInfos;

            if (arguments == null)
            {
                parameterInfos = new FickleParameterInfo[0];

                argumentExpressions = new Expression[0];
            }
            else if (arguments.GetType().IsAnonymousType())
            {
                var properties = arguments.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);

                var i = 0;
                argumentExpressions = new Expression[properties.Length];
                parameterInfos      = new FickleParameterInfo[properties.Length];

                foreach (var propertyInfo in properties)
                {
                    Type parameterType;
                    var  parameterName = propertyInfo.Name;
                    var  value         = propertyInfo.GetValue(arguments);

                    if (value is Expression)
                    {
                        parameterType          = ((Expression)value).Type;
                        argumentExpressions[i] = (Expression)value;
                    }
                    else
                    {
                        parameterType          = propertyInfo.PropertyType;
                        argumentExpressions[i] = Expression.Constant(value);
                    }

                    parameterInfos[i] = new FickleParameterInfo(parameterType, parameterName);


                    i++;
                }
            }
            else if (arguments is Expression)
            {
                parameterInfos = new FickleParameterInfo[]
                {
                    new FickleParameterInfo(((Expression)arguments).Type, "arg1")
                };

                argumentExpressions = new Expression[]
                {
                    (Expression)arguments
                };
            }
            else
            {
                parameterInfos = new FickleParameterInfo[]
                {
                    new FickleParameterInfo(arguments.GetType(), "arg1")
                };

                argumentExpressions = new Expression[]
                {
                    Expression.Constant(arguments)
                };
            }

            return(new Tuple <ParameterInfo[], Expression[]>(parameterInfos, argumentExpressions));
        }