public IEnumerable <DynaModuleSettingA> LoadFromFile(string file) { DynaModuleSettingPool <DynaModuleSettingA> pool = XmlHelper.Load <DynaModuleSettingPool <DynaModuleSettingA> >(file); if (pool == null) { return(null); } //// .NET 4.0 可能可以用Covariance方式直接傳回 //List<IDynaModuleSetting> tmp = new List<IDynaModuleSetting>(); //foreach( IDynaModuleSetting set in pool.Settings ) // tmp.Add(set); //return tmp; return(pool.Settings); }
public static void UT_DynaModule() { // Setting File DynaModuleSettingA sa = new DynaModuleSettingA() { ServiceCode = "SettingA" }; DynaModuleSettingA sb = new DynaModuleSettingA() { ServiceCode = "SettingB" }; DynaModuleSettingA sc = new DynaModuleSettingA() { ServiceCode = "SettingC" }; //DynaModuleASettingPool sp = new DynaModuleASettingPool(); DynaModuleSettingPool <DynaModuleSettingA> sp = new DynaModuleSettingPool <DynaModuleSettingA>(); sp.Settings.Add(sa); sp.Settings.Add(sb); sp.Settings.Add(sc); if (XmlHelper.Save("TmpSetting.xml", sp) == false) { Console.WriteLine("Save setting file failed"); } PluginInfo pi1 = new PluginInfo() { AssemblyFile = "DynaModuleImpl.dll", CreateType = "DynaModuleImpl.DynaModuleA", SettingLoaderType = "DynaModuleImpl.DynaModuleALoader", SettingFile = "TmpSetting.xml" }; string errMsg = ""; // 如果能知道最終型別的話,就使用最終型別作為泛型參數來呼叫 List <DynaModuleInfo <DynaModuleA, DynaModuleSettingA> > result = DynaModuleManager.LoadModuleInfo <DynaModuleA, DynaModuleSettingA>(pi1, ref errMsg); // 如果不知最終型別的話(可能是PlugIn的外掛模組),就用基底介面作為泛型參數來呼叫 // 這時SettingLoaderType必須是繼承自IDynaModuleSettingLoader<TSetting>的 List <DynaModuleInfo <IModule, ISetting> > resultBase = DynaModuleManager.LoadModuleInfo <IModule, ISetting>(pi1, ref errMsg); }