static void Main(string[] args) { IAssemblyTypeLoader assemblyTypeLoader = new AssemblyTypeLoader(); IAppConfiguration configuration = new AppConfiguration(); try { var inputDataProvider = assemblyTypeLoader.LoadType<IInputDataProvider>(configuration.ProviderFactoryAssemblyPath); var dataPersistor = assemblyTypeLoader.LoadType<IOutputDataPersistor>(configuration.ProviderFactoryAssemblyPath); LaunchSentenceProcessing(inputDataProvider, dataPersistor); } catch (ConfigurationErrorsException ex) { Console.WriteLine("An error occurred during the configuration load. Please check AppConfig is correctly set up. Error details: {0}", ex.Message); } catch(ArgumentNullException ex) { Console.WriteLine("An error occurred. Error details: {0}", ex.Message); } catch(ArgumentException ex) { Console.WriteLine("An error occurred. Provided path is incorrect. Error details: {0}", ex.Message); } catch (IOException ex) { Console.WriteLine("An error occurred during the assembly load. Please check if, dependencies are correctly set up. Error details: {0}", ex.Message); } catch (TypeLoadException ex) { Console.WriteLine("An error occurred during the assembly load. Error details: {0}", ex.Message); } Console.WriteLine("Application has finished running and will be closed after key press."); Console.ReadKey(); }
/// <summary> /// 根据Form的类型获取其实例 /// </summary> /// <param name="typeName">类型名</param> /// <param name="args">参数</param> /// <returns></returns> public static Control GetControl(string typeName, params object[] args) { string key = typeName;//获取窗体类的FullName Type ctrType = null; if (!dicType.TryGetValue(key, out ctrType)) { ctrType = _assemblyTypeLoader.LoadType(typeName); } return(GetControl(ctrType, args)); }
/// <summary> /// 通过Xml节点加载数据 /// </summary> /// <param name="node">节点</param> /// <param name="assemblyTypeLoader">节点</param> /// <returns></returns> public static Type LoadFromXmlNode(XmlNode node, AssemblyTypeLoader loader) { string assembly = null; string typeName = null; foreach (XmlAttribute att in node.Attributes) { if (att.Name.Equals("assembly", StringComparison.CurrentCultureIgnoreCase)) { assembly = att.InnerText; } else if (att.Name.Equals("type", StringComparison.CurrentCultureIgnoreCase)) { typeName = att.InnerText; } } return(loader.LoadType(typeName, assembly)); }