Methods 使用抽象方法对MethodBoundaryAspect进行后期处理

Methods 使用抽象方法对MethodBoundaryAspect进行后期处理,methods,abstract,postsharp,Methods,Abstract,Postsharp,我是PostSharp的新手,正在调查它在我们项目中的用途。我试图在抽象方法上应用OnMethodBoundaryAspect,并得到以下错误: 使用常规方法和虚拟方法可以很好地执行方面,我是否缺少任何东西,或者不可能使用抽象成员 以下是我的简单观点: [Serializable] public sealed class TraceAttribute : OnMethodBoundaryAspect { protected string _strMethodName; prote

我是PostSharp的新手,正在调查它在我们项目中的用途。我试图在抽象方法上应用OnMethodBoundaryAspect,并得到以下错误:

使用常规方法和虚拟方法可以很好地执行方面,我是否缺少任何东西,或者不可能使用抽象成员

以下是我的简单观点:

[Serializable]
public sealed class TraceAttribute : OnMethodBoundaryAspect
{
    protected string _strMethodName;
    protected static readonly Stopwatch _sw = new Stopwatch();

    public TraceAttribute(string pMethodName)
    {
        _strMethodName = pMethodName;
    }

    public override void OnEntry(MethodExecutionArgs args)
    {
        _sw.Start();
        string strMsg = string.Format(">> Entering {0}.{1}", args.Method.DeclaringType.Name, args.Method);
        Debug.Print(strMsg);
    }

    public override void OnExit(MethodExecutionArgs args)
    {
        _sw.Stop();
        string strMsg = string.Format("<< Leaving {0}.{1} - EXECTIME: {2} ms", args.Method.DeclaringType.Name,
                                      args.Method, _sw.ElapsedMilliseconds);
        Debug.Print(strMsg);

        _sw.Reset();
    }
}
[可序列化]
公共密封类跟踪属性:OnMethodBoundaryAspect
{
受保护字符串_strMethodName;
受保护的静态只读秒表_sw=新秒表();
公共TraceAttribute(字符串pMethodName)
{
_strMethodName=pMethodName;
}
public override void OnEntry(MethodExecutionArgs args)
{
_sw.Start();
string strMsg=string.Format(“>>输入{0}.{1}”,args.Method.DeclaringType.Name,args.Method);
调试打印(strMsg);
}
公共重写void OnExit(MethodExecutionArgs args)
{
_sw.Stop();

string strMsg=string.Format(“这可能是对我有用的副本-感谢您指出这一点!