1
완전히 신뢰할 수있는 코드를 실행하더라도 메서드의 런타임에 바인딩 호출이 MethodAccessException을 throw하는 성가신 상황이 있습니다.전용 멤버의 후기 바인딩 호출로 MethodAccessException이 throw됩니다.
나는 규칙에 따라 처리 논리를 일부 이벤트를 매핑하는 기본 클래스를 가지고는,이 핸들러는 IL 코드를 방출하여 만든 동적 방법을 사용하여 호출이 튜토리얼 다음 : http://www.codeproject.com/KB/cs/dynamicmethoddelegates.aspx
//in AssemblyA.dll:
public abstract class Base : IEventHandler
{
protected static void RegisterDerivedType(Type derived)
{
//create list of delegates to invoke event handlers
}
void IEventHandler.Handle(IEvent e)
{
//late bound invocation of appropriate handler method (e.g. EventX
//or EventY)
//this code throws a MethodAccessException
}
}
//in assemblyB.dll
public class Derived : Base
{
static Derived()
{
RegisterDerivedType(typeof(Derived));
}
private void OnEventX(EventX e) //EventX is derived of IEvent
{ }
private void OnEventY(EventY e) //EventY is derived of IEvent
{ }
}
다음과 같은 상황입니다 동적 메서드로 비공개 멤버를 호출 할 수없는 이유는 무엇입니까?