سؤال

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