Last active
May 27, 2016 03:46
-
-
Save Jalalx/0a1f321a9c514217e08e130c7a4b5871 to your computer and use it in GitHub Desktop.
Calling member method of a normal class without instantiating.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Foo | |
{ | |
public void Method1() | |
{ | |
Console.WriteLine("Method1: this == null: {0}", this == null); | |
} | |
} | |
var m1 = typeof(Foo).GetMethod("Method1"); | |
var method1 = Delegate.CreateDelegate(typeof(Action<Foo>), m1) as Action<Foo>; | |
method1(null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment