Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing Classes in the System Namespace

Tags:

.net

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?

Edit: 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.

like image 385
Serafina Brocious Avatar asked Jan 16 '10 14:01

Serafina Brocious


People also ask

What classes are in the System namespace?

The System namespace is the root namespace for fundamental types in . NET. This namespace includes classes that represent the base data types used by all applications, for example, Object (the root of the inheritance hierarchy), Byte, Char, Array, Int32, and String.

What is the use of System text in C#?

The System. Text namespace contains classes representing various character encoding and conversions, as well as providing helper classes for manipulating and formatting String objects. The StringBuilder class can be used in conjunction with the String class to manipulate a string.


1 Answers

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.

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.

[Except from page]

... 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.

[/Except from page]

like image 185
Gabriel McAdams Avatar answered Oct 16 '22 03:10

Gabriel McAdams