//</Snippet5> static public void MakeDynamic5() { //<Snippet5> // add the following directive to your file // using Microsoft.Scripting.Ast; //Instantiate the CallSiteBinder that describes the operation. var MyCallSiteBinder = new MyCallSiteBinder5(); //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, int, int>), MyCallSiteBinder, Expression.Constant(5), Expression.Constant(1), Expression.Constant(8), Expression.Constant(12), Expression.Constant(24), Expression.Constant(36) ); //Should print 86 Console.WriteLine(Expression.Lambda <Func <int> >(MyMakeDynamic).Compile().Invoke()); //</Snippet5> //Validate sample if (Expression.Lambda <Func <int> >(MyMakeDynamic).Compile().Invoke() != 86) { throw new Exception(""); } }
//</Snippet5> static public void MakeDynamic5() { //<Snippet5> // add the following directive to your file // using Microsoft.Scripting.Ast; //Instantiate the CallSiteBinder that describes the operation. var MyCallSiteBinder = new MyCallSiteBinder5(); //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, int, int>), MyCallSiteBinder, Expression.Constant(5), Expression.Constant(1), Expression.Constant(8), Expression.Constant(12), Expression.Constant(24), Expression.Constant(36) ); //Should print 86 Console.WriteLine(Expression.Lambda<Func<int>>(MyMakeDynamic).Compile().Invoke()); //</Snippet5> //Validate sample if (Expression.Lambda<Func<int>>(MyMakeDynamic).Compile().Invoke() != 86) throw new Exception(""); }