Postsharp:它是如何工作的? [英] Postsharp: how does it work?

查看:154
本文介绍了Postsharp:它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继咨询上了车的另外一个问题,我的转换code有报价与PostSharp使用:

Following the advice got on another question of mine, I converted the code there quoted to be used with PostSharp:

属性:

[Serializable]
public sealed class InitAttribute : OnMethodBoundaryAspect
{
    public override void OnEntry(MethodExecutionEventArgs eventArgs)
    {
        Console.Write("Works!");
    }
}


static class Logger
{
    public static string _severity;

    public static void Init(string severity)
    {
        _severity = severity;
    }

    [Init()]
    public static void p()
    {
        Console.WriteLine(_severity);
    }
}

不过,我不能得到任何结果(控制台上的作品!)。在PostSharp属性中的断点显示,永远不会进入的。

Still, I cannot get any result ("Works!" on the console). A breakpoint within the PostSharp attribute reveals that it is never entered.

任何帮助吗?先谢谢了。

Any Help? Thanks in advance.

推荐答案

PostSharp处理编译二进制IL,并添加你想要操作的方法饰有属性。该属性本身不会做任何事情。这是CLR如何往往工作。它只是把的属性的数据的,无法执行code。如果没有对编译code 运行PostSharp,你没有得到什么特别的东西。

PostSharp processes the compiled IL binary and adds action you want to the method body decorated with the attribute. The attribute won't do anything by itself. This is how CLR tends to work. It just treats attributes as data, not executable code. Without running PostSharp on the compiled code, you don't get anything special.

这篇关于Postsharp:它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆