Exemplo n.º 1
0
        public static bool Matches(Type controller, string methodName, string statement)
        {
            var method           = GetMethod(controller, methodName);
            var statementHandler = new ReflectionStatementDefinition(method, controller);

            return(statementHandler.Matches(new MatchingContext()
            {
                Statement = statement,
            }).Success);
        }
        public bool ItMatchesStatements(string statment, string statement)
        {
            var m     = GetMethod(statment);
            var load  = new ReflectionStatementDefinition(m, typeof(TestStatements));
            var match = load.Matches(new MatchingContext()
            {
                Statement = statement
            });

            return(match.Let(x => x.Success, false));
        }
Exemplo n.º 3
0
        public static InvokationResult Invoke <T>(Type controller, string methodName, T scope,
                                                  string statement, ContextBundle context = null, Func <object, bool> proceed = null)
        {
            if (proceed == null)
            {
                proceed = o => false;
            }
            context = context ?? new ContextBundle();
            var method           = GetMethod(controller, methodName);
            var statementHandler = new ReflectionStatementDefinition(method, controller);
            var invokationResult = new InvokationResult()
            {
                Context          = context,
                Statement        = statement,
                MatchingCriteria = statementHandler.GetMatchingCriteria(),
                Attachments      = new ContextBundle()
            };

            invokationResult.Match = statementHandler.Matches(new MatchingContext()
            {
                Statement = statement,
                ScopeType = typeof(T)
            });
            if (!invokationResult.Matched)
            {
                return(invokationResult);
            }
            var link = statementHandler.Link(statement);

            if (link == null)
            {
                throw new Exception("If matched, should have linked, but didn't");
            }
            invokationResult.Result = link.Execute(new InvokationContext()
            {
                Context     = invokationResult.Context,
                Attachments = invokationResult.Attachments,
                Scope       = scope,
                Proceed     = proceed
            });
            return(invokationResult);
        }