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