//</Snippet3> static public void MakeDynamic3() { //<Snippet3> // add the following directive to your file // using Microsoft.Scripting.Ast; //Instantiate the CallSiteBinder that describes the operation. var MyCallSiteBinder = new MyCallSiteBinder3(); //This Expression represents a dynamic operation. In this case, the Binder adds all arguments. Expression MyMakeDynamic = Expression.MakeDynamic( typeof(Func <CallSite, int, int, int, int>), MyCallSiteBinder, Expression.Constant(5), Expression.Constant(1), Expression.Constant(8) ); //Should print 14 Console.WriteLine(Expression.Lambda <Func <int> >(MyMakeDynamic).Compile().Invoke()); //</Snippet3> //Validate sample if (Expression.Lambda <Func <int> >(MyMakeDynamic).Compile().Invoke() != 14) { throw new Exception(""); } }
//</Snippet3> static public void MakeDynamic3() { //<Snippet3> // add the following directive to your file // using Microsoft.Scripting.Ast; //Instantiate the CallSiteBinder that describes the operation. var MyCallSiteBinder = new MyCallSiteBinder3(); //This Expression represents a dynamic operation. In this case, the Binder adds all arguments. Expression MyMakeDynamic = Expression.MakeDynamic( typeof(Func<CallSite, int, int, int, int>), MyCallSiteBinder, Expression.Constant(5), Expression.Constant(1), Expression.Constant(8) ); //Should print 14 Console.WriteLine(Expression.Lambda<Func<int>>(MyMakeDynamic).Compile().Invoke()); //</Snippet3> //Validate sample if (Expression.Lambda<Func<int>>(MyMakeDynamic).Compile().Invoke() != 14) throw new Exception(""); }