开发者

custom mscorlib.dll without native code

开发者 https://www.devze.com 2022-12-12 18:45 出处:网络
Is it possible to build custom mscorlib.dll without any use of native code (pinvoke allowed :-)? I\'ve tried a little experiment this weekend to see how hard it would be to do it and had following pr

Is it possible to build custom mscorlib.dll without any use of native code (pinvoke allowed :-)?

I've tried a little experiment this weekend to see how hard it would be to do it and had following proble开发者_如何学Cms:

  1. I've added one class System.Static to my version of mscorlib but had TypeLoadException with message that it can't load type 'System.Static`1' from 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. So it seems that somehow it's still loading MS library. How to avoid that (I'm using /nostdlib switch already)?.
  2. When I named my mscorlib 'mycorlib' I had errors that System.Object must have a parent class
  3. If I have generic type T and I'm doing new T() it's translated by c# compilator to Activator.CrateInstance<T>() which in MS implementation calls RuntimeTypeHandle.CreateInstance(...) which is native method. Can I call it from my mscorlib or is it included in mscorlib provided by MS?

My goal was to test the possibility of writing my versions of int, double, string and other standard types. I want to use MS CLR, but just provide my managed code classes.

Is it possible?


No it is not possible. Some types in corelib are too tied into the MS.Net implementation to be replaced by managed code.

You can try to to that with the mono runtime. But even then you will find that SOME (although very few) methods can not (or only with a HUGE overhead) be implemented in purely managed code.

One example for this would be the string class. While it can be mostly implemented in managed (see mono) things like Intern() cannot be simply and meaningful implemented managed-only. Also you will even get problems with the constructors in the case of string (which is per-def immutable!).

0

精彩评论

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