VB.NET与PostSharp和继承的类

时间:2012-12-17 17:58:26

标签: .net vb.net inheritance postsharp

我正在使用PostSharp捕获系统中使用类OnMethodBoundaryAspect生成的所有异常。它工作正常,但如果我需要在继承的某些类中获得异常,我在VB.NET中找不到解决方案。

MulticastAttributeUsageAttribute有一个带有一个validOn属性的构造函数,我只能设置MultcastTargets。该类有一个名为Inheritance的公共属性,但如果我在构造函数中设置它,它就没有效果。下面是一个例子:类B扩展了类A,属性方面在类A中注释,我需要方面自动看到类B.

如何解决这个问题?

代码

<Serializable()> _
<AttributeUsage(AttributeTargets.Class)> _
<MulticastAttributeUsage(MulticastTargets.Method)> _
Public Class ExceptionsAttribute
    Inherits OnMethodBoundaryAspect

        Public Overrides Sub OnEntry(ByVal Args As PostSharp.Aspects.MethodExecutionArgs)
             MyBase.OnEntry(Args)
        End Sub

        Public Overrides Sub OnException(ByVal Args As PostSharp.Aspects.MethodExecutionArgs)
             MyBase.OnException(Args)
        End Sub

    End Class

    <Exceptions()> _
    Public Class A

        Public Sub MethodA()
        End Sub

    End Class

    Public Class B
        Inherits A

        Public Sub MethodB()
        End Sub

    End Class

A类由Exception属性类注释。 B类扩展了A类,然后,我需要自动查看B类,而不需要使用Exception属性类进行注释。

1 个答案:

答案 0 :(得分:1)

解决!!!我需要直接设置属性,如:

<MulticastAttributeUsage(MulticastTargets.Method, Inheritance:=MulticastInheritance.Multicast)> 
相关问题