public static void Main(string[] args) { FindFindLanguageResource(JsonConfigurationHelper.GetAppSettingSingle("language")); string Value = GetStringValue(EnumSlightException.Login.ToString()); if (Value == null) { Console.WriteLine("该键值对不存在,请核对您输入的键值"); } Console.WriteLine(Value); Console.ReadKey(); }
///<summary> ///获取数据库连接 ///</summary> ///<return>IDbConnection</return> public IDbConnection CreateConnection() { IDbConnection connection = null;; //获取配置进行转换 //var type = JsonConfigurationHelper.GetAppSettingSingle("ComponentDbType"); //IServiceProvider serviceProvider = new ServiceCollection().BuildServiceProvider(); //var config = serviceProvider.GetService<IConfiguration>(); var type = JsonConfigurationHelper.GetAppSettingSingle("ComponentDbType"); var dbType = GetDataBaseType(type); //DefaultDatabase 根据这个配置项获取对应连接字符串 var database = JsonConfigurationHelper.GetAppSettingSingle("DefaultDatabase"); //var database = JsonConfigurationHelper.GetAppSettingSingle("DefaultDatabase",Config); if (string.IsNullOrEmpty(database)) { database = "mysql";//默认配置 } //var jsonConfigurationHelper = JsonConfigurationHelper.GetAppSettings<ConnectionStrings>("ConnectionStrings"); var strConn = JsonConfigurationHelper.GetAppSettingSingle("ConnectionStrings:" + database); //var strConn = JsonConfigurationHelper.GetAppSettingSingle("ConnectionStrings:" + database,Config); switch (dbType) { case DatabaseType.SqlServer: connection = new System.Data.SqlClient.SqlConnection(strConn); break; case DatabaseType.MySql: connection = new MySql.Data.MySqlClient.MySqlConnection(strConn); break; case DatabaseType.Oracle: connection = new Oracle.ManagedDataAccess.Client.OracleConnection(strConn); // connection = new System.Data.OracleClient.OracleConnection(strConn); break; default: connection = null; break; } return(connection); }