简体   繁体   English

没有本地代码的自定义mscorlib.dll

[英]custom mscorlib.dll without native code

Is it possible to build custom mscorlib.dll without any use of native code (pinvoke allowed :-)? 是否可以在不使用任何本地代码的情况下构建自定义mscorlib.dll(允许使用pinvoke :-)?

I've tried a little experiment this weekend to see how hard it would be to do it and had following problems: 这个周末我尝试了一个小实验,以了解这样做的难度,并遇到以下问题:

  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. 我已经在我的mscorlib版本中添加了一个类System.Static,但是具有TypeLoadException并带有消息,提示它无法从'mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089 。 So it seems that somehow it's still loading MS library. 因此,似乎仍以某种方式仍在加载MS库。 How to avoid that (I'm using /nostdlib switch already)?. 如何避免这种情况(我已经在使用/ nostdlib开关了)?
  2. When I named my mscorlib 'mycorlib' I had errors that System.Object must have a parent class 当我将我的mscorlib命名为“ mycorlib”时,出现错误,提示System.Object必须具有父类
  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. 如果我具有通用类型T,并且正在执行new T()它将由c#编译器转换为Activator.CrateInstance<T>() ,在MS实现中,该调用称为本地方法RuntimeTypeHandle.CreateInstance(...) Can I call it from my mscorlib or is it included in mscorlib provided by MS? 我可以从我的mscorlib调用它还是将它包含在MS提供的mscorlib中?

My goal was to test the possibility of writing my versions of int, double, string and other standard types. 我的目标是测试编写int,double,string和其他标准类型的版本的可能性。 I want to use MS CLR, but just provide my managed code classes. 我想使用MS CLR,但只提供我的托管代码类。

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. corelib中的某些类型太与MS.Net实现捆绑在一起,无法由托管代码替换。

You can try to to that with the mono runtime. 您可以尝试使用Mono运行时来实现这一点。 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. 尽管它大多数都可以在托管(请参见mono)中实现,但诸如Intern()类的东西却不能简单,有意义地仅由托管实现。 Also you will even get problems with the constructors in the case of string (which is per-def immutable!). 同样,在使用字符串的情况下,您甚至会遇到构造函数的问题(这是每定义不变的!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM