看点看起来像这样Postsharp - 介绍虚拟方法被调用,而不是覆盖方法
[Serializable]
[IntroduceInterface(typeof(ISomeMethod), OverrideAction = InterfaceOverrideAction.Ignore)]
public class MyAspect: InstanceLevelAspect, ISomeMethod
{
[IntroduceMember(IsVirtual = true, OverrideAction = MemberOverrideAction.Ignore)]
public string SomeMethod()
{
throw new NotImplementedException();
}
[OnMethodInvokeAdvice, MulticastPointcut(Targets = MulticastTargets.Method, Attributes = MulticastAttributes.Public)]
public void OnInvoke(MethodInterceptionArgs args)
{
var something = args.Instance as ISomeMethod;
//here is problem
string str = something.SomeMethod();
args.Proceed();
}
}
,当我在dotPeek检查,是的someMethod引入是虚拟的。 Aspect应用于与不同项目中的子类相同的基类。问题是当我重写此方法并调用OnInvoke拦截器时,SomeMethod方面实际上是用NotImplementedException而不是overriden方法调用的。调试器确认我在args.Instance中拥有正确的实例。这怎么可能?谢谢你的回答。
你的代码在哪里试图覆盖该方法看起来像什么? – Batavia
更多代码http://support.sharpcrafters.com/discussions/problems/3039-introduced-virtual-method-called-instead-overriden – sanjuro