using System; using System.Collections.Generic; using System.Text; using LinFu.Delegates; namespace ClosuresAndDynamicallyGeneratedMethods { class Program { static void Main() { CustomDelegate addMethodBody = delegate(object[] args) { int a = (int)args[0]; int b = (int)args[1]; return a + b; }; // Define the method signature Type returnType = typeof(int); Type[] parameterTypes = new Type[] { typeof(int), typeof(int) }; Closure closure = new Closure(addMethodBody, returnType, parameterTypes, 1, 1); int result = (int)closure.Invoke(); Console.WriteLine("The result is {0}", result); Console.WriteLine("Press ENTER to continue..."); Console.ReadLine(); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)