1

(或“一起使用 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

干杯

4

0 回答 0