看點看起來像這樣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