/// <summary> /// 加入多組元素(不強制取代) /// </summary> /// <param name="Self">Original Hashtable</param> /// <param name="Keys">Key</param> /// <param name="Value">Value</param> public static void AddDefualtItems(this Hashtable Self, string[] Keys, Object Value) { foreach (String Key in Keys) { Self.AddDefualtItem(Key, Value); } }
/// <summary> /// 載入參數 /// </summary> public static void LoadByDB() { lock (Settings) { Hashtable values = new Hashtable(); values.Add("Groups", ""); values.Add("Category", ""); values.Add("Keys", ""); values.Add("Value", ""); values.Add("ShowYN", ""); DataTable dt = Dao.SelectUSP("dbo.uspGetConfigsList", values, null, Setting.ConnectionString("SmsPlatform")); //DataTable dt = Dao.SelectUSP("dbo.uspGetConfigsList", values, null, Setting.GetConfig("Package", "Tools.Config", "ConfigDbConnection")); if (dt.Rows.Count > 0) { foreach (DataRow Row in dt.Rows) { String Groups = Row["Groups"].ToString(); String Category = Row["Category"].ToString(); String Keys = Row["Keys"].ToString(); String Value = Row["Value"].ToString(); Settings.AddDefualtItem(Groups, new Hashtable()); Settings.GetHashtable(Groups).AddDefualtItem(Category, new Hashtable()); Settings.GetHashtable(Groups).GetHashtable(Category).AddItem(Keys, Value); } } dt.Dispose(); } }
/// <summary> /// Object to Hashtable /// </summary> /// <param name="Contents"></param> /// <returns></returns> public static Hashtable ToHashTable(this object Contents) { Dictionary <string, object> dicSource = Contents.GetType() .GetProperties( BindingFlags.Instance | BindingFlags.Public ) .ToDictionary( prop => prop.Name, prop => prop.GetValue(Contents, null) ); Hashtable ht = new Hashtable(); foreach (KeyValuePair <string, object> kvp in dicSource) { ht.AddDefualtItem(kvp.Key, kvp.Value.ToString()); } return(ht); }