为什么比预编译代码注入有更好的主意? [英] Why is post-compilation code injection a better idea than pre-compilation code injection?

查看:68
本文介绍了为什么比预编译代码注入有更好的主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我们都知道C#没有类似C的宏预处理程序(关于为什么

So we all know that C# doesn't have a C-like macro pre-processor (and there's a good thread on why here). But now that AOP is gaining traction, it seems like we're starting to do stuff with post-processors that we used to do with pre-processors (bear in mind that I am only getting my feet wet with PostSharp so am perhaps off base).

我非常喜欢C#中的属性,但是如果出于充分原因而忽略了预处理器(作为前MFC用户,我仍然质疑但仍然接受),为什么编译后代码注入是一个更好的主意比预编译代码注入?

I am a huge fan of attributes in C#, but if a pre-processor was left out for good reasons (which, as a former MFC user I still question but nevertheless accept) why is post-compilation code injection a better idea than pre-compilation code injection?

推荐答案

5年前我在设计PostSharp时选择了编译后的原因是:

The reasons why I chose post-compilation when designing PostSharp 5 years ago are:

  1. 语言不可知论.
  2. 与高级语言(每两年更新一次)相比,MSIL的规范更稳定.
  3. 大多数时候,MSIL是您处理方面时所需的抽象级别.您不需要知道所有等效的构造(想想使用"和最终尝试").
  4. 在2008年之前,没有人能成功生产出像样的C#编译器.即使遇到了困难,Mono遇到的困难也令人印象深刻.
  5. 处理二进制文件似乎比处理源代码要快得多.
  6. 使用二进制程序集进行处理可以执行它-正在处理的程序集可以进行自身转换.首次发布PostSharp老挝之前闻所未闻.

也就是说,C/C ++的AOP实现确实是预编译器(WeaveC),而Java中的实现是编译器扩展(出于充分的理由,有很多Java编译器的OSS实现).

That said, implementations of AOP for C/C++ are indeed a pre-compiler (WeaveC) and implementations in Java are a compiler extension (for the good reason that there are many OSS implementations of the Java compiler).

-gael

这篇关于为什么比预编译代码注入有更好的主意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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