Created
August 22, 2011 03:17
-
-
Save peteraritchie/1161581 to your computer and use it in GitHub Desktop.
code to create an Action<T> that will call a method that takes an object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sbc.Subscribe(subs => | |
{ | |
Type type = GetRuntimeType(); // e.g. reflecting IHandle type... | |
//get pointer to generic method of specific type parameter | |
var methodInfo = subs.GetType().GetMethod("Handler", BindingFlags.Instance | BindingFlags.Public); | |
methodInfo = methodInfo.MakeGenericMethod(type); | |
// set up an action compatible with our method | |
// object is in commmon with any type we find above, so this will work | |
Action<object> a = m => serviceBus.Publish(m); | |
// following call to invoke is equivalent to: | |
// sbc.Handler<T>(m => serviceBus.Publish(m)); | |
methodInfo.Invoke(subs, new object[] {a}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment