//</Snippet2> static public void MakeDynamic2() { //<Snippet2> // add the following directive to your file // using Microsoft.Scripting.Ast; //Instantiate the CallSiteBinder that describes the operation. var MyCallSiteBinder = new MyCallSiteBinder2(); //This Expression represents a dynamic operation. Expression MyMakeDynamic = Expression.MakeDynamic( typeof(Func <CallSite, int, int, int>), MyCallSiteBinder, Expression.Constant(5), Expression.Constant(1) ); //Should print 6 Console.WriteLine(Expression.Lambda <Func <int> >(MyMakeDynamic).Compile().Invoke()); //</Snippet2> //Validate sample if (Expression.Lambda <Func <int> >(MyMakeDynamic).Compile().Invoke() != 6) { throw new Exception(""); } }
//</Snippet2> static public void MakeDynamic2() { //<Snippet2> // add the following directive to your file // using Microsoft.Scripting.Ast; //Instantiate the CallSiteBinder that describes the operation. var MyCallSiteBinder = new MyCallSiteBinder2(); //This Expression represents a dynamic operation. Expression MyMakeDynamic = Expression.MakeDynamic( typeof(Func<CallSite,int, int, int>), MyCallSiteBinder, Expression.Constant(5), Expression.Constant(1) ); //Should print 6 Console.WriteLine(Expression.Lambda<Func<int>>(MyMakeDynamic).Compile().Invoke()); //</Snippet2> //Validate sample if (Expression.Lambda<Func<int>>(MyMakeDynamic).Compile().Invoke() != 6) throw new Exception(""); }