using System; using System.Reflection; /// /// Contains the extension methods for . /// public static class DelegateExtensions { /// /// Dynamically invokes (late-bound) the method represented by the current /// delegate. /// /// Extended class. /// An array of objects that are the arguments to pass to the /// method represented by the current delegate. /// The object returned by the method represented by the delegate. /// /// The caller does not have access to the /// method represented by the delegate (for example, if the method is private); The /// number, order, or type of parameters listed in is invalid. /// One of the encapsulated methods /// throws an exception. public static object DynamicInvoke(this Delegate dlg, params object[] args) { return dlg.Method.Invoke(dlg.Target, BindingFlags.Default, null, args, null); } }