??????????ù?????(SettingManager)
???????????? ???????[ 2015/2/3 15:55:11 ] ???????????ù??? ??????????
???????????????????????????????CRUD??????
???????????????:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConfigManager
{
class Program
{
static void Main(string[] args)
{
var settings = ConfigManager.Appettings;
foreach(var item in settings)
{
Console.WriteLine("key:{0}??value:{1}"??item.Key??item.Value);
}
var t1 = ConfigManager.Appettings["key1"];
//test add
ConfigManager.Add("t"??"test");
//var t2 = ConfigManager.Appettings;
//update
ConfigManager.Update("t"??"test123");
//remove
ConfigManager.Remove("t");
Console.ReadKey();
}
}
}
??????????????С?
?????????????????!????????????
????//test not item in Dictionary
????var t2 = ConfigManager.Appettings["luckyhu"];
??????????????????!
???????????????????????????????????????????????????????.???????????????????????????.
?????????????????.
public class SettingManager : Dictionary<string?? string>
{
private static SettingManager _Settings = null;
public static SettingManager Settings
{
get
{
if (_Settings == null)
_Settings = new SettingManager();
return _Settings;
}
}
private SettingManager()
{
//Init Data
//DataSoure:truely data here...
for (int i = 0; i < 10; i++)
{
var key = String.Format("key{0}"?? i);
var value = String.Format("value{0}"?? i);
if (!this.Keys.Contains(key))
this.Add(key?? value);
}
}
public string this[string key]
{
get
{
if (!this.ContainsKey(key))
return String.Empty;
return base[key];
}
set
{
base[key] = value;
}
}
public static bool GetBoolValue(string key)
{
bool value = false;
bool.TryParse(Settings[key]?? out value);
return value;
}
public static int GetIntValue(string key)
{
int value = 0;
int.TryParse(Settings[key]?? out value);
return value;
}
}
????????????????????????????????:
????1.?????????
????2.????????????????????
????3.???????????Dictionary????????????CRUD
????4.??????????????????????
???????????Щ???????????????????.
?????e???????????????
????????????OK??
???????????????????????ù??????????? ????и???????????????????????????????????? .
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11