dll을 동적으로 불러오고 클래스 대상을list에 저장합니다.

2050 단어
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;
            }
        }

좋은 웹페이지 즐겨찾기