PC Review


Reply
Thread Tools Rate Thread

Create delegate from MethodInfo

 
 
Mike Scott
Guest
Posts: n/a
 
      14th Nov 2003
Given a MethodInfo for a static method (found using a custom attribute), I
want to create a delegate for it.

However, Delegate.CreateDelegate isn't supported on the Compact Framework
:-(

Does anyone know how to do this in C#?

Cheers,

MikeS.


 
Reply With Quote
 
 
 
 
Jonathan Wells [msft]
Guest
Posts: n/a
 
      14th Nov 2003
Hi Mike,

CreateDelegate is not support by the .NET Compact Framework. Take a look at
this thread and let us know if it helps:
http://groups.google.com/groups?q=co...tngxa09&rnum=2

j
--
Jonathan Wells
Product Manager
..NET Compact Framework
Check out the .NET Compact Framework FAQ at:
http://msdn.microsoft.com/mobility/p...Q/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.

"Mike Scott" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Given a MethodInfo for a static method (found using a custom attribute), I
> want to create a delegate for it.
>
> However, Delegate.CreateDelegate isn't supported on the Compact Framework
> :-(
>
> Does anyone know how to do this in C#?
>
> Cheers,
>
> MikeS.
>
>



 
Reply With Quote
 
Mike Scott
Guest
Posts: n/a
 
      14th Nov 2003
Hi Jonathan

Thanks for the link - but it's not what I'm looking for. Using interfaces is
what I'm doing at the moment, and I want to switch to using delegates. I
don't really want to have a class per method that I need to call. It's a
communications app and I want to be able to handle a set of messages, with
each message having a unique integer ID. I have a Hashtable into which I
insert a message handling delegate keyed by the message type ID. Using
reflection allows me easily to add new message handlers without having to
modify any existing code - I just add a method decorated with my custom
MessageHandlerAttribute. But the furthest I can get is to a MethodInfo. I
can't figure out a way to create the delegate dynamically.

However, I've worked around the missing Delegate.CreateDelegate() by
creating a small adapter class that takes the MethodInfo as a parameter to
its constructor. The class has a method which conforms to the delegate
signature so I just create a delegate to this method. This then just makes
the call on to the method that was discovered using reflection using
MethodInfo.Invoke.

Although Delegate.CreateDelegate() is missing on the CF, I was hoping there
was another way (e.g. using some other class) to create a delegate. It must
be possible - after all C# does it. Maybe I'll have to write some IL?

Cheers,

Mike.

"Jonathan Wells [msft]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Mike,
>
> CreateDelegate is not support by the .NET Compact Framework. Take a look

at
> this thread and let us know if it helps:
>

http://groups.google.com/groups?q=co...tngxa09&rnum=2
>
> j
> --
> Jonathan Wells
> Product Manager
> .NET Compact Framework
> Check out the .NET Compact Framework FAQ at:
>

http://msdn.microsoft.com/mobility/p...Q/default.aspx
>
> This posting is provided "AS IS" with no warranties, and confers no

rights.
>
> "Mike Scott" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Given a MethodInfo for a static method (found using a custom attribute),

I
> > want to create a delegate for it.
> >
> > However, Delegate.CreateDelegate isn't supported on the Compact

Framework
> > :-(
> >
> > Does anyone know how to do this in C#?
> >
> > Cheers,
> >
> > MikeS.
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare MethodInfo to delegate type? lee.chappers@googlemail.com Microsoft Dot NET Framework 1 15th Mar 2006 04:35 PM
Delegate Gurus: Can I create a delegate for a property (as opposed to a method)? Bill Davidson Microsoft C# .NET 6 3rd Aug 2005 04:19 PM
Create delegate from MethodInfo Stan Huff Microsoft C# .NET 2 14th Jun 2005 06:44 AM
Delegate's MethodInfo =?Utf-8?B?TWFyaW8gTWlmc3Vk?= Microsoft Dot NET Compact Framework 0 21st Mar 2005 08:43 AM
Re: Can I create a delegate for a property? Richard Grimes [MVP] Microsoft Dot NET Framework 0 14th Oct 2004 03:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:43 AM.