Exemplo n.º 1
0
        /// <summary>
        /// 默认获取应用程序所在的目录及子目录下的所有选项数据文件的文件路径
        /// </summary>
        /// <returns></returns>
        public static OptionXmlFile[] GetOptionFiles()
        {
            StringCollection     sc       = UtilityFile.SearchDirectory(OptionService.ApplicationStartPath, "*.option");
            List <OptionXmlFile> fileList = new List <OptionXmlFile>();

            foreach (var filePath in sc)
            {
                OptionXmlFile doc = new OptionXmlFile(filePath);
                fileList.Add(doc);
            }
            return(fileList.ToArray());
        }
Exemplo n.º 2
0
        public void Initializes(string optionFile)
        {
            string optionFilePath = string.Empty;

            if (File.Exists(optionFile))
            {
                optionFilePath = optionFile;
            }
            else
            {
                optionFilePath = Path.Combine(ApplicationStartPath, optionFile);
            }

            this.OptionFile = OptionFile.Load(optionFilePath);

            this.OptionDocument = new XmlDocument();
            this.OptionDocument.Load(optionFilePath);

            StringCollection files = UtilityFile.SearchDirectory(ApplicationStartPath, "*.dll", true, true);

            foreach (string file in files)
            {
                Assembly ass   = Assembly.LoadFile(file);
                Type[]   types = ass.GetTypes();
                foreach (Type type in types)
                {
                    if (type.IsDefined(typeof(OptionAttribute), false))//如果Class被定制特性标记
                    {
                        object[] objs = type.GetCustomAttributes(false);
                        foreach (var obj in objs)
                        {
                            if (!(obj is OptionAttribute))
                            {
                                continue;
                            }
                            Option[] options = Option.Load(ass, type, (OptionAttribute)obj);
                            foreach (Option o in options)
                            {
                                o.OptionChangingEvent += new Option.OptionChangingEventHandler(OptionChangingEvent);
                            }
                        }
                    }
                }
            }
        }