How to cast implicitly on a reflected method call

前端 未结 3 904
我寻月下人不归
我寻月下人不归 2021-02-18 13:08

I have a class Thing that is implicitly castable from a string. When I call a method with a Thing parameter directly the cast from s

3条回答
  •  不知归路
    2021-02-18 13:51

    In this specific case you can make the conversion through the array type, that is

    showThingReflected.Invoke(this, new Thing[] {"foo"});
    

    but that's a kind of "cheating". In general, you cannot expect the Invoke to consider your user-defined implicit operator. This conversion must be inferred compile-time.

提交回复
热议问题