动态加载dll,并创建类对象放入到list中。
private List<IVisualControlsPlug> visualPlugs = new List<IVisualControlsPlug>(); public void Load() { DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); foreach (FileInfo fi in di.GetFiles("VisualControls.*.dll")) { Assembly lib = Assembly.LoadFrom(fi.FullName); foreach (Type t in lib.GetExportedTypes()) { if (t.GetInterface(typeof(IVisualControlsPlug).FullName) != null) { IVisualControlsPlug plug = (IVisualControlsPlug)Activator.CreateInstance(t); InitializePlugin(Env.Current, plug); } } } } private void InitializePlugin(IEnvironment env, IVisualControlsPlug plug) { plug.Initialize(env); visualPlugs.Add(plug); } //重载操作符 public IVisualControlsPlug this[string pluginId] { get { foreach (IVisualControlsPlug plug in visualPlugs) if (plug.PluginId == pluginId) return plug; return null; } }
posted on 2015-12-25 11:19 strangeman 阅读(495) 评论(0) 编辑 收藏 举报