Ejemplo n.º 1
0
        public TypeDispatchNode Add(TypeDispatchNode root, RuleDeclaration declaration)
        {
            ConditionDeclaration[] conditions  = declaration.Conditions.ToArray();
            Expression[]           expressions = conditions.Select(x => _normalizer.Normalize(x.Expression)).ToArray();

            var visitor = new FindConditionVisitor(expressions);

            root.Visit(visitor);

            object[] conditionNodes = visitor.ExistingNodes;

            for (int i = 0; i < conditions.Length; i++)
            {
                if (conditionNodes[i] == null)
                {
                    conditionNodes[i] = CreateConditionNode(root, conditions[i].MatchType, expressions[i]);
                }
            }

            Node joinNode = CreateJoinNode(conditionNodes, conditions[0].MatchType);

            declaration.Consequences.Each(consequence =>
            {
                CreateActionNode(joinNode, consequence.Expression);
            });

            return(root);
        }
Ejemplo n.º 2
0
        private Node CreateConditionNodeOfT <T>(TypeDispatchNode root, Expression <Func <T, bool> > expression)
        {
            var conditionNode = new ConditionNode <T>(expression);

            root.Add(conditionNode);

            return(conditionNode);
        }
Ejemplo n.º 3
0
        protected bool Visit(TypeDispatchNode node)
        {
            _lastNodeVertex = GetSink(node.GetHashCode(), () => "Rules", typeof(TypeDispatchNode), typeof(object));

            if (_stack.Count > 0)
            {
                _edges.Add(new Edge(_stack.Peek(), _lastNodeVertex, _lastNodeVertex.TargetType.Name));
            }

            return(true);
        }
Ejemplo n.º 4
0
 private Node CreateConditionNode(TypeDispatchNode root, Type matchType, Expression expression)
 {
     return(this.FastInvoke <DeclarationCompiler, Node>(new[] { matchType }, "CreateConditionNodeOfT", root, expression));
 }
Ejemplo n.º 5
0
        protected bool Visit(TypeDispatchNode node)
        {
            Append("MatchType");

            return(true);
        }