在C#中使用Assembly實現插件機制可以通過以下步驟實現:
public interface IPlugin
{
void DoSomething();
}
public class MyPlugin : IPlugin
{
public void DoSomething()
{
Console.WriteLine("Plugin is doing something...");
}
}
Assembly assembly = Assembly.LoadFrom("PluginAssembly.dll");
Type pluginType = assembly.GetType("MyPlugin");
IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType);
plugin.DoSomething();
通過以上步驟,可以實現在C#中使用Assembly實現插件機制,動態加載并使用插件功能。