Esempio n. 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);
        }
        public void AddArgumentValue_AddsArgument()
        {
            MethodInvocationContext context = new MethodInvocationContext();
            context.AddArgumentValue(5);

            DatasourceFactory factory = context.GetArguments().First();
            Assert.NotNull(factory);
        }
        public void AddArgumentSource_AddsArgument()
        {
            MethodInvocationContext context = new MethodInvocationContext();
            context.AddArgumentSource(typeof(RandomStringSource));

            DatasourceFactory factory = context.GetArguments().First();
            Assert.NotNull(factory);
        }
Esempio n. 4
0
        public IEngineConfigurationTypeBuilder <TPoco> Invoke <TReturn>(Expression <Func <TPoco, TReturn> > func)
        {
            MethodInvocationContext context = GetMethodArgs(func);
            String name = ReflectionHelper.GetMethodName(func);

            this.SetupMethod(name, context);
            return(this);
        }
Esempio n. 5
0
        public IEngineConfigurationTypeBuilder <TPoco> Invoke(Expression <Action <TPoco> > action)
        {
            MethodInvocationContext context = GetMethodArgs(action);
            String name = ReflectionHelper.GetMethodName(action);

            this.SetupMethod(name, context);
            return(this);
        }
 public void RegisterMethod(MethodInfo method, MethodInvocationContext context)
 {
     EngineTypeMember member = ReflectionHelper.GetMember(method);
     if (mType.GetRegisteredMember(member) == null)
     {
         mType.RegisterMember(member);
     }
     IEngineConfigurationTypeMember registeredMember = mType.GetRegisteredMember(member);
     registeredMember.SetDatasources(context.GetArguments().Cast<IEngineConfigurationDatasource>());
 }
        public void RegisterMethod(MethodInfo method, MethodInvocationContext context)
        {
            var member = ReflectionHelper.GetMember(method);

            if (mType.GetRegisteredMember(member) == null)
            {
                mType.RegisterMember(member);
            }
            var registeredMember = mType.GetRegisteredMember(member);

            registeredMember.SetDatasources(context.GetArguments().Cast <IEngineConfigurationDatasource>());
        }
        public IEngineConfigurationTypeBuilder SetupMethod(string methodName, MethodInvocationContext context)
        {
            DatasourceFactory[] factories = context.GetArguments().ToArray();
            MethodInfo          info      = mType.GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(x =>
                                                                                                                x.Name == methodName &&
                                                                                                                x.GetParameters().Length == factories.Length)
                                            .FirstOrDefault();

            if (info == null)
            {
                throw new ArgumentException("Method does not exist", methodName);
            }

            var memberBuilder = new EngineConfigurationTypeMemberBuilder(ReflectionHelper.GetMember(info), this);

            mMembers.Add(memberBuilder);
            memberBuilder.SetDatasources(factories);

            return(this);
        }
        public IEngineConfigurationTypeBuilder SetupMethod(string methodName, MethodInvocationContext context)
        {
            DatasourceFactory[] factories = context.GetArguments().ToArray();
            MethodInfo info = mType.GetMethods(BindingFlags.Public | BindingFlags.Instance).Where(x =>
                x.Name == methodName
                && x.GetParameters().Length == factories.Length)
                .FirstOrDefault();

            if (info == null) { throw new ArgumentException("Method does not exist", methodName); }

            var memberBuilder = new EngineConfigurationTypeMemberBuilder(ReflectionHelper.GetMember(info), this);
            mMembers.Add(memberBuilder);
            memberBuilder.SetDatasources(factories);

            return this;
        }