How to Get Reference to Method from MethodInfo (C#)
c#, reflection
Solution
Try to use CreateDelegate method. It will work only if you know method`s signature.
http://msdn.microsoft.com/en-us/library/system.delegate.createdelegate.aspx
UPD (tnx to Chris Sinclair):
example of using
lookup.Add(methodInfo.Name
, (SkillEffect)Delegate.CreateDelegate(typeof(SkillEffect), methodInfo));
Problem
I'm trying to build a dictionary that indexes each static method in a class so they can be looked up with a string. I can't seem to find a way to actually get a reference back to the method from the MethodInfo. Is this possible? ``` delegate void SkillEffect(BattleActor actor, BattleActor target); public static class SkillEffectLookup { public static Dictionary<string, SkillEffect> lookup; public static void Build() { lookup = new Dictionary<string, SkillEffect>(); Type type = typeof(SkillEffects); var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public); foreach (MethodInfo methodInfo in methods) { lookup.Add(methodInfo.Name, _____________); } } public static class SkillEffects { public static Attack(BattleActor actor, BattleActor target) { // Do Things } public static NonAttack(BattleActor actor, BattleActor target) { // Do Other Things } } ```