How do I use reflection to invoke a private method?

后端 未结 10 800
说谎
说谎 2020-11-22 14:05

There are a group of private methods in my class, and I need to call one dynamically based on an input value. Both the invoking code and the target methods are in the same i

10条回答
  •  误落风尘
    2020-11-22 14:24

    Are you absolutely sure this can't be done through inheritance? Reflection is the very last thing you should look at when solving a problem, it makes refactoring, understanding your code, and any automated analysis more difficult.

    It looks like you should just have a DrawItem1, DrawItem2, etc class that override your dynMethod.

提交回复
热议问题