문제

I'm looking for a way to call a private method from a base class in a derived classes with the TypeBuilder. I know this can be done by simply invoking the method via reflection but attempting to call a passthrough method generated with the typebuilder results in a MethodAccessException. Has anyone found a way around this issue?

도움이 되었습니까?

해결책

There is no "issue". You're not allowed to call private methods - that's why they're private. The fact that you can do so with reflection when you've got suitable trust is effectively a backdoor, not an indication that it's something you should be able to do in other ways.

If at all possible you should redesign to avoid the desire to call the private method. If you absolutely have to call it, use reflection - the fact that that's ugly is an indication that you're in an ugly situation.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top