开发者

How to create my own System namespace and objects?

It is said here http://msdn.microsoft.com/en-us/library/fa13yay7%28v=VS.90%29.aspx (see also http://msdn.microsoft.com/en-us/library/s4wcexbc%28VS.90%29.aspx)

Use this option if you want to define or create your own System namespace and objects.

But how ? Where can I find some examples ?

Update: of course my que开发者_Go百科stion is not about how to create a namespace or a class but about an example of custom system architecture (an UML schema and source code).

For example could this be used to port .NET on other processors like iphone ? Does Mono use this ?

Is there some smallest possible example instead of whole commercial clr to learn from ?


How? Just write the code. Make a namespace called System that contains a class called Object and a class called String, and the compiler will pick that up and use it instead of the framework class library version. That's how the framework team does it. All you have to do is replicate all their work yourself and you too can be in the framework class library providing business.

Note that in many cases the compiler has been designed to expect that the types in the System namespace are exactly as they are documented to be. I've had bug reports in the past - extremely confusing bug reports! - where someone has redefined, say, System.Collections.Generic.IEnumerator<T> to have different properties and methods than the "real" one, and then they're all surprised and vexed that the compiler generates crazy broken code for a "foreach" loop. If redefining the basic interfaces is the sort of thing you want to do, consider writing your own C# compiler too. Ours is by design not robust in that scenario.


I don't know why you want to do that but you just have to create a custom "System" assembly (like a standard library) and use it as a reference in your other project with /nostdlib+ set.

namespace System 
{
  public sealed class String : IComparable, ICloneable, IConvertible, IComparable<string>, IEnumerable<char>, IEnumerable, IEquatable<string>
  {
     ...
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜