通过AssemblyInfo应用PostSharp方面

时间:2013-10-21 03:56:14

标签: aop postsharp aspect

我想将VerboseTraceAspect应用于我的解决方案,并将该属性应用于除

之外的所有地方
  1. 吸气剂和二传手
  2. TestProject.Logging.*TestProject.Tracing.*
  3. 中的任何类型

    我正在使用以下示例,但它似乎不起作用。我做错了吗?如果是这样,应该怎么做?

    谢谢你。

    [assembly: VerboseTraceAspect(AspectPriority = 0, AttributeExclude = true, AttributeTargetTypes = "TestProject.Logging.*|TestProject.Tracing.*")]
    
    [assembly: VerboseTraceAspect(AspectPriority = 1, AttributeExclude = true, AttributeTargetMembers = "regex:get_.*|set_.*")]
    
    [assembly: VerboseTraceAspect(AspectPriority = 2, AttributeTargetTypes = "TestProject.*", 
        AttributeTargetTypeAttributes = MulticastAttributes.Public, 
        AttributeTargetMemberAttributes = MulticastAttributes.Public, 
        AttributeTargetElements = MulticastTargets.Method)] 
    

1 个答案:

答案 0 :(得分:2)

您需要更正从TestProject.Logging.*TestProject.Tracing.*删除跟踪属性的第一行中的目标类型表达式。如果要指定使用管道分隔的多个选项,则应使用正则表达式语法。

您还需要使用AttributePriority代替AspectPriority属性。属性多播是在AspectPriority产生任何影响之前执行的。稍后会用它来确定方面的执行顺序。

“exclude”属性必须具有更高的优先级值(在较低值之后处理较高的值)。

[assembly: VerboseTraceAspect(
    AttributePriority = 1,
    AttributeExclude = true,
    AttributeTargetTypes = @"regex:TestProject\.Logging\..+|TestProject\.Tracing\..+")]

[assembly: VerboseTraceAspect(
    AttributePriority = 2,
    AttributeExclude = true,
    AttributeTargetMembers = "regex:get_.*|set_.*")]

[assembly: VerboseTraceAspect(
    AttributePriority = 0,
    AttributeTargetTypes = "TestProject.*",
    AttributeTargetTypeAttributes = MulticastAttributes.Public,
    AttributeTargetMemberAttributes = MulticastAttributes.Public,
    AttributeTargetElements = MulticastTargets.Method)] 
相关问题