Delegate.CreateDelegate fail to call correct overloaded function..
im try to make (C# - WinForm like) Style Editor UI System. so new EditorWindow("MethodHaveClass") is going to make at runtime(exactly, this class is inherited UnityEditor.EditorWindow class.) . then Controls ("EventHaveClass") added on EditorWindow. in this case. i think i need this reflection code.. to use added controls.. here is the code
[CODE] public class MethodHaveClass() :EditorWindow { public static void ClickEventTest() { Debug.Log("Clicked!!"); }
public class EventHaveClass() { public delegate void CustomEvent(); public event CustomEvent OnClicked; }
public class ButtonControl : EventHaveClass() { public void Init(string methodClassName, string methodName, string eventClassName string eventName) { Type methodClassType = Type.GetType(methodClassName); MethodInfo m_Info = methodClassType.GetMethod(methodName);
Type eventClassType = Type.GetType(eventClassName); EventInfo m_event = eventClassType.GetEvent(eventName);
Delegate handler = Delegate.CreateDelegate(m_event.EventHandlerType, m_Info); // <- exception m_event.AddEventHandler(eventClassType, handler); } } [/CODE] and Delegate.CreateDelegate function makes exception below.
ArgumentException: method argument length mismatch System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Delegate.cs:226) ButtonControl.Init (System.String id, System.String windowName, Rect rect, System.String controlName, System.String LClick, System.String RClick, System.String texturePath) (at Assets/Editor/CustomEditor/Controls/ButtonControl.cs:48) UnityEditor.GenericMenu.CatchMenu (System.Object userData, System.String[] options, Int32 selected) (at C:/buildslave/unity/build/artifacts/generated/common/editor/GenericMenuBindings.gen.cs:122)
i want to use CreateDelegate(Type, MethodInfo) this type of overload method but in exception message says "CreateDelegate(Type, Object, MethodInfo, Boolean) " with ArgumentException: method argument length mismatch. exception. how can i fix it? or Something wrong Delegate.CreateDelegate function with Unity 5.3.4f1?