同組件:
Type type = Type.GetType(ConfigurationManager.AppSettings["LogType"]);
ILog log = (ILog)Activator.CreateInstance(type);
log.Write(new Exception("異常測試"));
跨組件:
string asmPath = Path.Combine(Environment.CurrentDirectory, "LogClassLibrary.dll");
Assembly asm = Assembly.LoadFrom(asmPath);
Type type = asm.GetType(ConfigurationManager.AppSettings["LogType"]);
ILog log = (ILog)type.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
log.Write(new Exception("異常測試"));

public interface IHost
{
List Plugins { get; }
int LoadPlugins(string path);
ILog GetLog(string name);
}
public interface ILog
{
bool Write(string message);
bool Write(Exception ex);
}
外掛程式設計要點:以介面定義外掛契約,宿主透過介面發現、載入、執行外掛。所有外掛實作必須實作該介面。反射的動態載入能力使此架構成為可能。