Esempio n. 1
0
        internal void ExtractParameters(LambdaExpression methodLambda)
        {
            var mex = methodLambda.Body as MethodCallExpression;

            if (mex == null)
            {
                ErrorMessages.RTE0008_FluentWithMethodError.Throw();
            }
            var mi = mex.Method;

            var methodParameters = mi.GetParameters();

            if (methodParameters.Length == 0)
            {
                return;
            }


            var i = 0;

            foreach (var expression in mex.Arguments)
            {
                var pi = methodParameters[i];
                i++;

                var call = expression as MethodCallExpression;
                if (call != null)
                {
                    if (call.Method.IsGenericMethod &&
                        call.Method.GetGenericMethodDefinition() == Ts.ParametrizedParameterMethod)
                    {
                        var pcb = new ParameterExportBuilder(Blueprint, pi);

                        var parsed = false;
                        var arg    = call.Arguments[0] as LambdaExpression;
                        if (arg != null)
                        {
                            var delg = arg.Compile();
                            delg.DynamicInvoke(pcb);
                            parsed = true;
                        }
                        var uarg = call.Arguments[0] as UnaryExpression; // convert expression
                        if (uarg != null)
                        {
                            var operand = uarg.Operand as MethodCallExpression;
                            if (operand != null)
                            {
                                var actionArg = operand.Object as ConstantExpression;
                                if (actionArg != null)
                                {
                                    var value = actionArg.Value as MethodInfo;
                                    if (value != null)
                                    {
                                        var param     = Expression.Parameter(typeof(ParameterExportBuilder));
                                        var newCall   = Expression.Call(value, param);
                                        var newLambda = Expression.Lambda(newCall, param);
                                        var delg      = newLambda.Compile();
                                        delg.DynamicInvoke(pcb);
                                        parsed = true;
                                    }
                                }
                            }
                            if (!parsed)
                            {
                                ErrorMessages.RTE0009_FluentWithMethodCouldNotParse.Throw(call.Arguments[0]);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 ///     Specifies code generator for member
 /// </summary>
 public static ParameterExportBuilder WithCodeGenerator <T>(this ParameterExportBuilder conf)
     where T : TsCodeGeneratorBase <ParameterInfo, RtArgument>
 {
     conf.Attr.CodeGeneratorType = typeof(T);
     return(conf);
 }
Esempio n. 3
0
 /// <summary>
 ///     Specifies code generator for member
 /// </summary>
 public static ParameterExportBuilder WithCodeGenerator <T>(this ParameterExportBuilder conf, T codeGeneratorInstance)
     where T : TsCodeGeneratorBase <ParameterInfo, RtArgument>
 {
     conf.Attr.CodeGeneratorInstance = codeGeneratorInstance;
     return(conf);
 }
Esempio n. 4
0
 /// <summary>
 ///     Sets parameter default value.
 /// </summary>
 /// <param name="conf">Configuration</param>
 /// <param name="value">Default value for parameter</param>
 public static ParameterExportBuilder DefaultValue(this ParameterExportBuilder conf, object value)
 {
     conf.Attr.DefaultValue = value;
     return(conf);
 }