Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```CSharp
- LoadPlugins<IStoreProvider>("载入数据访问插件", TCNCConsts.TcncPluginDir_DataAccess);
- LoadPlugins<IProtocolProvider>("载入协议支持插件", TCNCConsts.TcncPluginDir_Protocol);
- /// <summary>
- /// 插件设置
- /// </summary>
- private void PluginSetting()
- {
- Notice.Notice("执行插件设置");
- Thread.Sleep(300);
- string priPath = "Plugins\\DataAccess;Plugins\\Protocol;";
- AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", priPath);
- AppDomain.CurrentDomain.SetData("BINPATH_PROBE_ONLY", priPath);
- var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);
- var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
- m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", priPath });
- }
- /// <summary>
- /// 载入插件
- /// </summary>
- private List<T> LoadPlugins<T>(string msg, string pluginDir) where T : class
- {
- Notice.Notice(msg);
- string storePluginDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pluginDir);
- var files = Directory.GetFiles(storePluginDir);
- List<T> stores = new List<T>();
- files.SafeForEach(file =>
- {
- if (file.EndsWith(".dll"))
- {
- Assembly ass = Assembly.LoadFrom(file);
- ass.GetTypes().SafeForEach(t =>
- {
- Type ti = typeof(T);
- if (ti.IsAssignableFrom(t))
- {
- var iStore = t.GetInstance() as T;
- stores.Add(iStore);
- }
- });
- }
- });
- return stores;
- }
- ```
Add Comment
Please, Sign In to add comment