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:
- 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)?.
- When I named my mscorlib 'mycorlib' I had errors that System.Object must have a parent class
- If I have generic type T and I'm doing
new T()
it's translated by c# compilator toActivator.CrateInstance<T>()
which in MS implementation callsRuntimeTypeHandle.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!).
精彩评论