Weird. I have a column that covers that the just went live yesterday.

The problem you have is that when creating a delegate, you need to have
a type that matches it, but in the general case, you don't.

I got around it by using reflection.emit to create the appropriate type
on the fly. This is an okay method if you're going to call it a bunch,
but if you only want to call it once, InvokeMember() is a lot easier.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol
/html/csharp02172004.asp

Hope that helps

Eric
-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Ryan Parlee
Sent: Monday, March 01, 2004 10:39 PM
To: [EMAIL PROTECTED]
Subject: [ADVANCED-DOTNET] Creating a delegate from reflection
information

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?

Thanks,
Ryan

===================================
This list is hosted by DevelopMentor(r)  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

===================================
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