简体   繁体   English

用户定义的C#中的ClassLoader

[英]User Defined ClassLoader In C#

Inspired by this question why do we need user defined classloader in java 受这个问题的启发, 为什么我们需要Java中的用户定义的类加载器

Does C# have a way of defining a way to load classes and dlls on demand C#是否具有定义按需加载类和dll的方法

您可以处理AppDomain.AssemblyResolve事件以手动加载运行时无法自行定位的程序集。

.NET offers a lot of options for resolving/configuring assembly/type names while loading. .NET提供了许多在加载时解析/配置程序集/类型名称的选项。 But ultimately, look at Assembly.Load & Assembly.LoadFrom methods - you may even load types from some custom storage using these methods. 但最终,请看Assembly.Load和Assembly.LoadFrom方法-您甚至可以使用这些方法从某些自定义存储中加载类型。

No, and why would you want something like that? 不,为什么要这样呢?

The only reason I can think of is for injection/mocking. 我能想到的唯一原因是注射/模拟。

For that you would use the .NET profiler API, and rewrite IL on the fly. 为此,您将使用.NET事件探查器API,并即时重写IL。

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

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