Пример #1
0
        //</Snippet1>

        static public void MakeDynamic1()
        {
            //<Snippet1>
            // add the following directive to your file
            // using Microsoft.Scripting.Ast;

            //Instantiate the CallSiteBinder that describes the operation.
            var MyCallSiteBinder = new MyCallSiteBinder();


            //This Expression represents a dynamic operation.
            Expression MyMakeDynamic = Expression.MakeDynamic(
                typeof(Func <CallSite, int, int>),
                MyCallSiteBinder,
                Expression.Constant(5)
                );


            //Should print 6
            Console.WriteLine(Expression.Lambda <Func <int> >(MyMakeDynamic).Compile().Invoke());

            //</Snippet1>

            //Validate sample
            if (Expression.Lambda <Func <int> >(MyMakeDynamic).Compile().Invoke() != 6)
            {
                throw new Exception("");
            }
        }
Пример #2
0
        //</Snippet1>

        static public void MakeDynamic1() {
            //<Snippet1>
            // add the following directive to your file
            // using Microsoft.Scripting.Ast;  

            //Instantiate the CallSiteBinder that describes the operation.
            var MyCallSiteBinder = new MyCallSiteBinder();
            

            //This Expression represents a dynamic operation.
            Expression MyMakeDynamic = Expression.MakeDynamic(
                typeof(Func<CallSite,int, int>),
                MyCallSiteBinder,
                Expression.Constant(5)
            );
            

            //Should print 6
            Console.WriteLine(Expression.Lambda<Func<int>>(MyMakeDynamic).Compile().Invoke());

            //</Snippet1>

            //Validate sample
            if (Expression.Lambda<Func<int>>(MyMakeDynamic).Compile().Invoke() != 6) throw new Exception("");
        }