public static T GetConfig <T>(string name = null) where T : class, IConfigFile { if (name == null) { name = AttributeHelper.GetCustomAttribute(typeof(T)).Name; } IConfigFile instance = null; if (configFiles.TryGetValue(name, out instance)) { return(instance as T); } instance = PluginProvider.GetObjectInstance <IConfigFile>(name) ?? PluginProvider.GetObjectInstance(typeof(T)) as IConfigFile; try { instance.ReadConfig(instance.SavePath); } catch (Exception ex) { instance.RebuildConfig(); instance.SaveConfig(); } configFiles.Add(name, instance); return(instance as T); }
public static IConfigFile GetConfig(string name = null) { XFrmWorkAttribute first = PluginProvider.GetFirstPlugin(typeof(IConfigFile), name); if (first == null) { return(null); } IConfigFile instance = null; if (configFiles.TryGetValue(first.Name, out instance)) { return(instance); } try { instance = PluginProvider.GetObjectInstance <IConfigFile>(first.Name); instance.ReadConfig(instance.SavePath); } catch (Exception ex) { if (instance == null) { throw new Exception("不包含任何有关配置文件的任何信息,请检查"); } instance.RebuildConfig(); instance.SaveConfig(); } configFiles.Add(first.Name, instance); return(instance); }