I used CSharpCodeProvider to compile and generate a new namespace in the memory for temporary use only. But this namespace should be deleted from the memory after certain period of time in order to allow for the next generated code to override the same identifiers of all generated classes and methods.

有帮助吗?

解决方案

There is only one way a loaded type can be unloaded: if it is a part of a collectible assembly.

But collectible assemblies can be only created through Reflection.Emit, not CSharpCodeProvider. Because of that, I'm not sure if using a collectible assembly is an option for you. If not, you will need some other option (like unloading AppDomains).

其他提示

No way. Class unload only happens - attention - when unloading a AppDomain.

Your best bet is to do all the code generation in a child-appdomain (will be same process), but that will not be trivial (the child appdomain needs proxies of all reachable object via remoting).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top