Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Operations operationObj = new Operations();

            ArithmeticHandler arithObj1, arithObj2, arithObj3;

            arithObj1  = new ArithmeticHandler(operationObj.Addition);
            arithObj1 += new ArithmeticHandler(operationObj.Subtraction);
            arithObj2  = new ArithmeticHandler(operationObj.Addition);
            arithObj2 -= new ArithmeticHandler(operationObj.Subtraction);
            ////Multicasting a delegate
            //arithObj3 = arithObj1 + arithObj2;
            //Anonymous Method
            ArithmeticHandler  arithobj1 = delegate(int n1, int n2) { Console.WriteLine("Addition of {0} and {1} is {2}", n1, n2, n1 + n2); };
            ArithmeticHandler1 arithobj2 = delegate(int n1, int n2) { return(n1 - n2); };

            ////Lambda Expression
            ArithmeticHandler  arithobj3 = (n1, n2) => { Console.WriteLine("Addition of {0} and {1} is {2}", n1, n2, n1 + n2); Console.WriteLine("Hello"); };
            ArithmeticHandler1 arithobj4 = (n1, n2) => n1 - n2; //(x)=>n;()=>2;

            //arithObj1(2, 3);
            // arithObj2(30, 2);
            arithobj3(6, 20);
            // arithobj2(6, 3);
            // arithobj1(20, 4);
            //arithobj4(10, 4);
            Console.WriteLine(arithobj4(10, 4));
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //Using Anonymous Method
            ArithmeticHandler arithObj01 = delegate(int firstNumber, int secondNumber)
            {
                Console.WriteLine("Addition of {0} and {1} is {2}", firstNumber, secondNumber, firstNumber + secondNumber);
            };

            arithObj01(3, 4);

            //Using Lambda Expression
            ArithmeticHandler arithObj02 = (firstNumber, secondNumber) => { Console.WriteLine("Addition of {0} and {1} is {2}", firstNumber, secondNumber, firstNumber + secondNumber); };

            arithObj02(3, 4);

            Console.ReadKey();
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Initializes static members of the <see cref="FlowQueryHelper" /> class.
        /// </summary>
        static FlowQueryHelper()
        {
            ExpressionHandlerLock = new object();

            CustomExpressionHandlers = new Dictionary <ExpressionType, HashSet <IExpressionHandler> >();

            DefaultExpressionHandlers = new Dictionary <ExpressionType, HashSet <IExpressionHandler> >();

            AddCallHandler(new AsHandler());
            AddCallHandler(new SimpleMethodCallHandler(Projections.Avg, "Average"));
            AddCallHandler(new LikeHandler());
            AddCallHandler(new CountDistinctHandler());
            AddCallHandler(new SimpleMethodCallHandler(Projections.Count, "Count"));
            AddCallHandler(new SimpleMethodCallHandler(Projections.GroupProperty, "GroupBy"));
            AddCallHandler(new SimpleMethodCallHandler(Projections.Max, "Max"));
            AddCallHandler(new SimpleMethodCallHandler(Projections.Min, "Min"));
            AddCallHandler(new ProjectHandler());
            AddCallHandler(new RoundHandler());
            AddCallHandler(new SubqueryHandler());
            AddCallHandler(new SubstringHandler());
            AddCallHandler(new SimpleMethodCallHandler(Projections.Sum, "Sum"));
            AddCallHandler(new TrimHandler());
            AddCallHandler(new TrimEndHandler());
            AddCallHandler(new TrimStartHandler());

            var conditionHandler = new ConditionHandler();

            ConditionHandler.SupportedExpressionTypes.ForEach(x => AddHandler(x, conditionHandler));

            var arithmeticHandler = new ArithmeticHandler();

            ArithmeticHandler.SupportExpressionTypes.ForEach(x => AddHandler(x, arithmeticHandler));

            AddHandler(ExpressionType.Add, new ConcatenationHandler());
            AddHandler(ExpressionType.Coalesce, new CoalesceHandler());
            AddHandler(ExpressionType.Conditional, new ConditionalHandler());
            AddHandler(ExpressionType.Convert, new ConvertHandler());
            AddHandler(ExpressionType.Lambda, new LambdaHandler());
            AddHandler(ExpressionType.MemberAccess, new MemberAccessHandler());
            AddHandler(ExpressionType.MemberInit, new MemberInitHandler());
            AddHandler(ExpressionType.New, new NewHandler());
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            Operations operationObj = new Operations();

            ArithmeticHandler arithObj1, arithObj2, arithObj3;

            arithObj1 = new ArithmeticHandler(operationObj.Addition);
            arithObj2 = new ArithmeticHandler(operationObj.Subtraction);

            //Multicasting a delegate
            arithObj3 = arithObj1 + arithObj2;

            arithObj1(2, 3);

            arithObj2(3, 2);

            arithObj3(6, 4);

            Console.ReadKey();
        }