Beispiel #1
0
        private void visitorPatternBtn_Click(object sender, RoutedEventArgs e)
        {
            // emulate 1+2+3
            var expr = new Addition(
                new Addition(
                    new Literal(1),
                    new Literal(2)
                    ),
                new Literal(3)
                );

            var expr1 = new Subtraction(
                new Subtraction(
                    new Literal(1),
                    new Literal(2)
                    ),
                new Literal(3)
                );

            var sb = new StringBuilder();
            var expressionPrinter = new ExpressionPrinter(sb);

            expr.Accept(expressionPrinter);
            expr1.Accept(expressionPrinter);
            Console.WriteLine(sb);

            // dynamic visitior
            //TODO why it breaks on this code ???
            //emulate 1 + 2 + 3
            //var expr2 = new DynamicAddition(
            //  new DynamicAddition(
            //    new DynamicLiteral(1),
            //    new DynamicLiteral(2)
            //  ),
            //  new DynamicLiteral(3)
            //);

            //var sb1 = new StringBuilder();
            //DynamicExpressionPrinter.Print((dynamic)expr2, sb);
            //Console.WriteLine(sb);
        }