【问题标题】:PostSharp cannot exclude aspect from TargetMembersPostSharp 不能从 TargetMembers 中排除方面
【发布时间】:2020-09-10 16:27:42
【问题描述】:

我正在工作的项目是使用 PostSharp v4.2 来应用日志记录等方面。这些方面应用于 AssemblyInfo.cs 中的多播目标,并且它们工作正常。 多播的定义如下

[assembly: LoggingAspect.LogAspect(AttributeTargetTypes = "regex:Api.Controllers.Services.*|Api.Controllers.Bananas.*", 
AttributeTargetMembers = "regex:Get.*|Create.*|Edit.*|Delete.*"
AspectPriority = 1, AttributeExclude = false)]

现在我需要从记录中排除 2 个方法。所以排除我添加的方法:

[assembly: LoggingAspect.LogAspect(AttributeTargetMembers = "GetUtilityToken", AspectPriority = 2, AttributeExclude = true)]

我不知道为什么,但方面仍然适用于方法(GetUtilityToken、GetDevUtility),即使我应用了documentation 中所述的排除方法。我什至尝试使用正则表达式或通配符(如AttributeTargetMembers = "Get*" )进行定位但方面仍然得到应用。我看过这个问题PostSharp - excluding a method using AttributeExclude doesn't work,但我在那个方法中没有 LINQ 查询..

我无法弄清楚我错过了什么......谁能指出可能导致这种行为的原因?或指出我该如何调试?

【问题讨论】:

    标签: c# aop postsharp


    【解决方案1】:

    您应该使用 AttributePriority 而不是 AspectPriority。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多