(或“一起使用LocationInterceptionAspect和IInstanceScopedAspect”)
使用Postsharp我试图使用'IntroduceMember'将属性注入目标类,然后使用LocationInterceptionAspect的'OnGetValue'功能动态地给它一个检查值。
最初我认为我需要两个单独的方面,一个用于字段注入,一个用于位置拦截,但设法通过实现IInstanceScopedAspect接口并从LocationInterceptionAspect继承来组合这两个方面。
问题在于,如果我设置断点,我将看到已经注入的属性,但是如果我在OnGetValue方法中设置另一个断点(为类中的每个属性触发),我看不到它。
以下是一些示例代码:
[Serializable]
class DALDecoratorWrapper : LocationInterceptionAspect, IInstanceScopedAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
if (args.LocationName == "Type")
{
args.Value = "computed value here";
}
args.ProceedGetValue();
}
[IntroduceMember(OverrideAction = MemberOverrideAction.OverrideOrFail)]
public String Type { get; set; }
我也希望有更好的方法来做到这一点,而不是覆盖OnGetValue,因为每个getter都会调用它,我真的想要只针对已经注入的属性的getter
干杯