1 static void Main(string[] args)
2 {
3 WriteIL("M1");
4 WriteIL("M2");
5 Console.Read();
6 }
7
8 void M1()
9 {
10 int a = 0;
11 }
12
13 void M2()
14 {
15 int a = 0;
16 Console.WriteLine(a);
17 }
18
19 private static void WriteIL(string method)
20 {
21 Type tp = (new Program()).GetType();
22
23 MethodInfo mi = tp.GetMethod(method,
24 BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
25
26 MethodBody mb = mi.GetMethodBody();
27 byte[] bt = mb.GetILAsByteArray();
28
29 StringBuilder sb = new StringBuilder();
30 for (int i = 0; i < bt.Length; i++)
31 {
32 sb.Append(bt[i].ToString("X2"));
33 sb.Append(" ");
34 }
35
36 Console.WriteLine(sb.ToString());
37 }
2 {
3 WriteIL("M1");
4 WriteIL("M2");
5 Console.Read();
6 }
7
8 void M1()
9 {
10 int a = 0;
11 }
12
13 void M2()
14 {
15 int a = 0;
16 Console.WriteLine(a);
17 }
18
19 private static void WriteIL(string method)
20 {
21 Type tp = (new Program()).GetType();
22
23 MethodInfo mi = tp.GetMethod(method,
24 BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
25
26 MethodBody mb = mi.GetMethodBody();
27 byte[] bt = mb.GetILAsByteArray();
28
29 StringBuilder sb = new StringBuilder();
30 for (int i = 0; i < bt.Length; i++)
31 {
32 sb.Append(bt[i].ToString("X2"));
33 sb.Append(" ");
34 }
35
36 Console.WriteLine(sb.ToString());
37 }