MethodInfo.CreateDelegate example ?
-
Wednesday, January 04, 2012 8:55 AMCan you give us a code example of CreateDelegate using MethodInfo ?
All Replies
-
Thursday, January 05, 2012 3:02 PM
Can you give us a code example of CreateDelegate using MethodInfo ?
I need to create a Delegate for an Event Handler. -
Monday, January 09, 2012 8:56 AMModerator
Try below code:
partial class MainPage { public MainPage() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { A a = new A(); TypeInfo t = this.GetType().GetTypeInfo(); MethodInfo m = t.GetDeclaredMethod("a_AeventHanlder"); Delegate d = m.CreateDelegate(typeof(dele), this); a.A_event += (dele)d; } string a_AeventHanlder(string p) { return ""; } } public delegate string dele(string p); public class A { public event dele A_event; }Sincerely,
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Rob CaplanMicrosoft Employee, Moderator Thursday, January 19, 2012 7:59 PM
-
Monday, January 09, 2012 11:21 AMOK. Thanks !


