What you want is called open instance delegate . It is not directly supported in C #, but the CLR supports it.
In principle, an open instance delegate is the same as a normal delegate, but before normal parameters it takes an additional parameter for this and has a zero target (for example, a delegate for a static method). For example, the open equivalent of an instance of Action<T> would be:
delegate void OpenAction<TThis, T>(TThis @this, T arg);
Here is a complete example:
void Main() { MethodInfo sayHelloMethod = typeof(Person).GetMethod("SayHello"); OpenAction<Person, string> action = (OpenAction<Person, string>) Delegate.CreateDelegate( typeof(OpenAction<Person, string>), null, sayHelloMethod); Person joe = new Person { Name = "Joe" }; action(joe, "Jack");
See this article for more details.
Thomas levesque
source share