コード例 #1
0
        private MethodInvocationContext GetMethodArgs(MethodCallExpression methodExpression)
        {
            MethodInvocationContext context = new MethodInvocationContext();

            foreach (var arg in methodExpression.Arguments)
            {
                switch (arg.NodeType)
                {
                case ExpressionType.Call:

                    MethodCallExpression paramCall = arg as MethodCallExpression;

                    // Extract the data source type
                    Type     sourceType  = ExtractDatasourceType(paramCall);
                    Object[] factoryArgs = ExtractDatasourceParameters(paramCall);

                    context.AddArgumentSource(sourceType, factoryArgs);

                    break;

                case ExpressionType.Constant:

                    // Simply pop the constant into the list
                    ConstantExpression paramConstant = arg as ConstantExpression;
                    context.AddArgumentValue(paramConstant);
                    break;

                default:
                    throw new ArgumentException("Unsupported argument used in method invocation list", "methodExpression");
                }
            }

            return(context);
        }
コード例 #2
0
        public void AddArgumentValue_AddsArgument()
        {
            MethodInvocationContext context = new MethodInvocationContext();
            context.AddArgumentValue(5);

            DatasourceFactory factory = context.GetArguments().First();
            Assert.NotNull(factory);
        }