/// <summary> /// 添加一个DataTypePlugin /// </summary> /// <param name="plugIn"></param> public void AddDataTypePlugin(IDataTypePlugin plugIn) { if (!instance.DataTypePlugins.Keys.Contains(plugIn.Name)) { instance.DataTypePlugins.Add(plugIn.Name, plugIn); } }
/// <summary> /// 从动态库文件加载DataTypePlugin /// </summary> /// <param name="assemblyFile"></param> public void LoadDataTypePlugin(string assemblyFile) { string ext = assemblyFile.Substring(assemblyFile.LastIndexOf(".")); Assembly dll; if (ext != ".dll") { throw new Exception(ErrorMessages.NotValidFileError); } try { dll = Assembly.LoadFile(assemblyFile); } catch (Exception) { throw new Exception(ErrorMessages.FileNotFoundError); } Type[] types = dll.GetTypes(); foreach (Type type in types) { if (typeof(IDataProcesser).IsAssignableFrom(type)) { IDataTypePlugin dataTypePlugIn = (IDataTypePlugin)Activator.CreateInstance(type, myCoreService); AddDataTypePlugin(dataTypePlugIn); } } }