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