You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
using System.Configuration; |
|
|
|
namespace BrilliantSightClient.Model.Helper; |
|
|
|
public class ConfigurationHelper |
|
{ |
|
static System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); |
|
/// <summary> |
|
/// 读取配置Key |
|
/// </summary> |
|
/// <param name="key"></param> |
|
/// <returns></returns> |
|
public static string ReadConfigValue(string key) |
|
{ |
|
|
|
try |
|
{ |
|
string name = config.AppSettings.Settings[key].Value; |
|
|
|
return name; |
|
} |
|
catch (Exception e) |
|
{ |
|
return ""; |
|
} |
|
} |
|
|
|
public static int ReadConfigValueToInteger(string key, int defaultV = 0) |
|
{ |
|
if (int.TryParse(ReadConfigValue(key), out int i)) |
|
{ |
|
return i; |
|
} |
|
else |
|
{ |
|
return defaultV; |
|
} |
|
} |
|
|
|
/// <summary> |
|
/// 写入配置 |
|
/// </summary> |
|
/// <param name="key"></param> |
|
/// <param name="value"></param> |
|
public static void SetConfigValue(string key, string value) |
|
{ |
|
config.AppSettings.Settings[key].Value = value; |
|
config.Save(ConfigurationSaveMode.Modified); |
|
System.Configuration.ConfigurationManager.RefreshSection("appSettings"); |
|
} |
|
} |