Ryan Parlee schrieb:
I am wanting to create a delegate at runtime using reflection but am unable
to get this working.  Specifically, I would like to something like this:


foreach (MethodInfo mi in this.GetType().GetMethods(BindingFlags.Instance)) { myDelegate = new MyDelegate(mi.MethodHandle) myArray.Add(myDelegate); }


The compiler complains that new MyDelegate() expects a method. Is there a way to do what I want to do?

Use Delegate.CreateDelegate. However: I just found that there is no overload that takes an instance _and_ a MethodInfo (which is a bit strange, since there is an overload that takes a MethodInfo for static methods), so maybe you will get problems with overloaded methods, when the string representation fits several methods.

Fabian

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to