是静态的情况下总是一个在C#中?静态、情况下

2023-09-03 08:49:54 作者:顾梓染℡

我有一个静态字段中的库。我想创建一个应用程序,并引用这个库,所以我想有这样的静态字段的两个实例。 .NET运行库不允许引用同一个库两次,但我不知道是否有可能克服这种限制?

I have a library that has a static field inside. I want to create an app and reference this library so I'd have two instances of this static field. .Net runtime does not allow to reference the same library twice, but I wonder is it possible to overcome this limitation?

我不能改变图书馆,但我可以复制/重命名。

I'm not allowed to change the library, but I can copy/rename it.

推荐答案

这并不像你想象的那样疯狂。事实上,你可以做到这一点使用的AppDomain 。

That's not as crazy as you think. In fact, you can achieve this using AppDomains.

每个 的AppDomain 具有静态变量自己的存储位置。所以,你可以创建你的进程第二的AppDomain,并使用一个对象,它继承了 MarshalByRefObject的像的这个MSDN例如。