在系统命名空间更换类 [英] Replacing Classes in the System Namespace

查看:145
本文介绍了在系统命名空间更换类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在砍我的.NET操作系统插入MS.NET/Mono(previously也只跑了裸机)上运行,并且我已经打了一个小的障碍。我需要实现我自己的System.Console,讨论我的服务基础设施,我不能找到一个好办法来替代它不要么1)不链接对mscorlib程序(将hellacious做),或2)使用NotQuiteSystem命名空间我的替代品,这将破坏兼容性。

I'm currently working to hack my .NET operating system into running on top of MS.NET/Mono (previously it ran bare-metal only), and I've hit a small snag. I need to implement my own System.Console that talks to my service infrastructure, and I can't find a good way to replace it without either 1) not linking against mscorlib (would be hellacious to do), or 2) Using a NotQuiteSystem namespace for my replacements, which would break compatibility.

有没有一种机制,使我可以清晰地替换系统类没有做的事情之一?

Is there a mechanism by which I can cleanly replace System classes without doing one of those things?

编辑:一个想到的是用Mono.Cecil能做到改写引用System.Console到Renraku.System.Console或诸如此类,但我preFER到如果可能的范围内正常工作

One thought is to use Mono.Cecil to rewrite references to System.Console to Renraku.System.Console or somesuch, but I'd prefer to work within the framework if possible.

推荐答案

您应该考虑的免费工具 PostSharp 。它可以让你通过自动MSIL的修改改变现有的.NET程序集在设计时。

You should look into the free tool PostSharp. It allows you to change existing .Net assemblies at design time by automating the modification of the MSIL.

请参阅此页在编译时编织的PostSharp更多信息。和此页织(负载时信息出现在之前的运行时间组件加载在内存中)。

See this page for more information on compile-time weaving in PostSharp. and this page for information on load-time weaving (occurs at runtime just before the assembly is loaded in memory).

有关运行时织(在运行时修改现有的方法),看看李林甫

For Runtime weaving (modifying existing methods at runtime), look at LinFu.

[除了从页]

...您可以使用LinFu.AOP动态拦截任何方式在任何类型的,不管方法是否宣告虚拟的还是非虚。您还可以动态地拦截(甚至替换)在密封类型声明的方法,除了那些在该类型声明的任何静态方法。

... you can use LinFu.AOP to dynamically intercept any method on any type, regardless of whether or not the method is declared virtual or non-virtual. You’ll also be able to dynamically intercept (and even replace) methods declared on sealed types, in addition to any static methods that are declared on that type.

[/除了从页]

这篇关于在系统命名空间更换类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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