16

在功能、易用性、文档、示例、社区/支持、VS 集成、已知实现、长期可行性和构建自定义 AOP 框架的构建速度方面,哪个更好?

我将从我所知道的开始(到目前为止我只尝试过 PostSharp):

  • Microsoft Common Compiler Instrastruture (CCI):我读过它用于 FxCop、ILMerge、Spec# 和代码合同。它似乎是非常低的级别,因为它甚至不负责纠正使用它修改 IL 时被破坏的分支代码的偏移量
  • PostSharp已经 5 岁了,具有许多 AOP 功能(例如,抽象了一些您需要手动完成的事情,而 IL 离开),源代码可用,仅由一个人开发/支持,但他正计划将其作为一项业务,有文档但可能会更好,构建需要大约两倍的时间,关于如何注入 IL 的样本非常少,并且版本 2.0 将很快发布,这有望得到很大改进。
  • Mono Cecil:由一个人编写,是 Mono 套件的一部分,并且有一个名为 Reflexil 的 Reflector 插件,它使用 Mono Cecil。
4

3 回答 3

6

Microsoft.CCI 和 Mono.Cecil 都是低级的,不验证生成的程序集。如果生成的代码或汇编结构中存在任何错误,则需要花费大量时间来查找问题原因。
如果它的功能足以完成您的任务,我建议使用 PostSharp。
否则... Mono.Cecil 具有更好、更易理解和易于使用的对象模型。然而,当我在我的程序中使用它时遇到了一个丑陋的错误(对错误方法的引用保存在程序集中;我认为元数据令牌处理存在一些错误)
Microsoft.CCI 有一个丑陋的,完全过度设计的对象模型同时缺少许多简单的功能;但是,它比 Mono.Cecil 更成熟。最后,我放弃了 Mono.Cecil,并在我的程序中使用了 Microsoft.CCI。

于 2009-09-06T04:22:59.900 回答
3

与已经存在的大多数框架一样,关于实现自己的 AOP 框架,我建议您:不要这样做。已经有几个,包括(即将成为)商业支持的 PostSharp 和CTru,一个由Typemock提供支持的 AOP 框架。

但无论如何,我发现 Mono.Cecil 非常好用。它抽象出很好地处理的需要Reflection.Emit,并且得到了 Mono 社区的支持。

我建议你看看LinFu - 它是一组开源库,其中一个是在 Mono.Cecil 之上实现的 AOP 框架。CodeProject上有一篇关于LinFu AOP的好文章。

于 2009-09-05T10:10:41.940 回答
3

AFAIK,LinFu 是建立在 Mono.Cecil 上的。

I would say that PostSharp.Core has more high-level features than other frameworks, so it's less difficult to use for larger works. You can work at low level too, but not at binary level (by design). You could do an assembly merger/shrinker using PostSharp, but the fact that it compiles back using ILASM would set some limitations (for instance that even internal members should be named). On the other side, having ILASM as the backend makes it much easier to develop on the top of PostSharp, since ILASM verify many rules and you can easily read the produced MSIL code. PostSharp even let you put comments into MSIL to help debugging code generation.

Another point: if you want to do a custom aspect (for instance, you develop a database engine and want to deliver a persistence aspect), you need much more than just an MSIL rewriter. You need an AO infrastructure that will do much of the job for you. When you are developing a custom aspect, I would say 1% of the work is specific to your custom aspect, 39% is the aspect infrastructure, and 60% is the MSIL rewriter stuff. I am often able to program a very specific aspect in a couple of hours based on PostSharp.

So, back to your question, and of course with my own biais, I would say: if you want to write an obfuscator, merger/shrinker and so on, rather go for Mono.Cecil or Microsoft.CCI for the only reason that their license if more friendly than PostSharp's one. But if just want to develop a custom aspect, using PostSharp will make you save weeks, and you would be surprised by commercial conditions we could offer if you plan to redistribute PostSharp.

于 2009-09-06T17:56:14.320 回答