c# - Create a delegate when the exact type of the argument is unknown -
i have troubles create right delegate instance method:
public t addcomponent<t>() t : component { .... }
i using reflection specific methodinfo , on delegate.createdelegate getting error binding target method
private delegate t addcomponent<out t>(); private static addcomponent<component> addc { get; set; } public void test() { var go = new gameobject(); var targetaddcomponent = typeof (gameobject).getmethods().first(m => m.name == "addcomponent" && m.getparameters().length == 0); addc = (addcomponent<component>) delegate.createdelegate(typeof (addcomponent<component>), go, targetaddcomponent, true); .... }
do have clues on doing wrong?
the method info method info method gameobject.addcomponent<t>
, returns t. delegate, have incredibly confusingly named same method, must method returns component
. have done cause t equal component? nothing.
put way: method info method info isn't callable method until constructed. it's generic pattern making methods, not method. make method if want make delegate it. need supply type argument type parameter t in method.
Comments
Post a Comment