Esempio n. 1
0
        private void LoadComponents()
        {
            string path           = AppContext.Current.AppCache["baseDir"] + "com\\";
            Type   targetFormType = typeof(Form);

            foreach (string filePath in Directory.GetFiles(path, "*.dll"))
            {
                var asy        = Assembly.LoadFile(filePath);
                var configType = asy.GetTypes().FirstOrDefault(t => t.GetInterface("ICompoentConfig") != null);
                if (configType != null)
                {
                    ICompoent compoent = null;
                    var       config   = (ICompoentConfig)Activator.CreateInstance(configType);
                    config.CompoentRegister(AppContext.Current, out compoent);
                    if (compoent != null)
                    {
                        foreach (Type formType in compoent.FormTypes)
                        {
                            if (targetFormType.IsAssignableFrom(formType))
                            {
                                AppContext.Current.AppFormTypes.Add(formType.FullName, formType);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public void CompoentRegister(IAppContext context, out ICompoent compoent)
        {
            AppContext = context;
            var compoentInfo = new Compoent("Com.First", "V16.3.26.1.1");

            compoentInfo.AddFormTypes(typeof(Form1), typeof(Form2)); //将认为需要用到的窗体类型添加到预注册列表中

            compoent = compoentInfo;                                 //回传Compoent的实例
        }