5 public static int Main(string[] args)
7 DerivedClass o = new DerivedClass();
9 Func<string> del1 = GetDel1 (o);
10 Func<string> del2 = GetDel2 (o);
13 Console.WriteLine("Action\n======\nReflected type: {0}\nDeclaring type: {1}\nAttributes: {2}\nResult: {3}",
14 del1.Method.ReflectedType, del1.Method.DeclaringType, del1.Method.Attributes, del1 ());
18 Console.WriteLine("Delegate\n========\nReflected type: {0}\nDeclaring type: {1}\nAttributes: {2}\nResult: {3}",
19 del2.Method.ReflectedType, del2.Method.DeclaringType, del2.Method.Attributes, del2 ());
21 if (del1.Method.ReflectedType != typeof (DerivedClass))
23 if (del1.Method.DeclaringType != typeof (DerivedClass))
25 if (del1 () != "Derived method")
28 if (del2.Method.ReflectedType != typeof (DerivedClass))
30 if (del2.Method.DeclaringType != typeof (DerivedClass))
32 if (del2 () != "Derived method")
35 if (!del1.Equals (del2))
37 if (!del2.Equals (del1))
43 static Func<string> GetDel1 (DerivedClass o)
48 static Func<string> GetDel2 (DerivedClass o)
50 return (Func<string>) Delegate.CreateDelegate(typeof(Func<string>), o, o.GetMethod().Method);
56 public Func<string> GetMethod()
61 public virtual string MyMethod()
67 class DerivedClass : BaseClass
69 public override string MyMethod()
71 return "Derived method";