Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Generic Thread Start

, 22 Mar 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Another approach is to use a generic delegate-factory class. Essentially, the class has a field of generic type, a delegate field which accepts an argument of that type, an parameterless instance method which accepts an argument of that type and invokes the delegate with it, and a static method...
Another approach is to use a generic delegate-factory class. Essentially, the class has a field of generic type, a delegate field which accepts an argument of that type, an parameterless instance method which accepts an argument of that type and invokes the delegate with it, and a static method which accepts a delegate of the same type as the field, along with the parameter that should be passed to that delegate. It creates a new class instance using the parameter values as fields, and returns a new delegate to invoke the instance method.
 
If I need a MethodInvoker which will execute foo(bar), e.g. to pass to a SetCallback function, I simply write something like (VB syntax):
  SetCallback(InvokeMaker.Create(AddressOf foo, bar))
I have a family of such classes/factories for up to four parameters. Very handy.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

supercat9
Web Developer
Unknown
Embedded systems programmer since 1994.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 22 Mar 2011
Article Copyright 2011 by supercat9
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid