public static bool?GetBool(this StrObjDict dict, string key) { var obj = Get(dict, key); if (IsNullOrEmpty(obj)) { return(null); } if (obj.ToString().ToLower().Equals("true")) { return(true); } if (obj.ToString().ToLower().Equals("false")) { return(false); } if (int.TryParse(obj.ToString(), out int obj1)) { return(obj1 != 0); } else { return(null); } }
public void Add(StrObjDict value) { if (value == null) { return; } foreach (var item in value) { Add(item.Key, item.Value); } }
public static DateTime?GetDateTime(this StrObjDict dict, string key) { var obj = Get(dict, key); if (IsNullOrEmpty(obj)) { return(null); } if (DateTime.TryParse(obj.ToString(), out DateTime obj1)) { return(obj1); } else { return(null); } }
public static decimal?GetDecimal(this StrObjDict dict, string key) { var obj = Get(dict, key); if (IsNullOrEmpty(obj)) { return(null); } if (decimal.TryParse(obj.ToString(), out decimal obj1)) { return(obj1); } else { return(null); } }
public static int?GetInt(this StrObjDict dict, string key) { var obj = Get(dict, key); if (IsNullOrEmpty(obj)) { return(null); } if (int.TryParse(obj.ToString(), out int obj1)) { return(obj1); } else { return(null); } }
private static object Get(StrObjDict dict, string key) { if (string.IsNullOrEmpty(key)) { return(null); } if (dict.ContainsKey(key)) { return(dict[key]); } else if (dict.ContainsKey(key.ToUpper())) { return(dict[key.ToUpper()]); } else if (dict.ContainsKey(key.ToLower())) { return(dict[key.ToUpper()]); } else { return(dict.FirstOrDefault(op => op.Key.ToUpper().Equals(key.ToUpper()))); } }
public static string GetString(this StrObjDict dict, string key) { var obj = Get(dict, key); return(obj?.ToString()); }
public static object GetObject(this StrObjDict dict, string key) { var obj = Get(dict, key); return(obj); }
// //扩展Get方法 // public static bool IsNullOrEmpty(this StrObjDict dict, string key) { var obj = Get(dict, key); return(IsNullOrEmpty(obj)); }
public static IList <StrObjDict> GetSods(this StrObjDict dict, string key) { var obj = Get(dict, key); return(JsonHelper.Deserialize <IList <StrObjDict> >(obj)); }
public static StrObjDict GetSod(this StrObjDict dict, string key) { var obj = Get(dict, key); return(JsonHelper.Deserialize <StrObjDict>(obj)); }
public static bool GetBool2(this StrObjDict dict, string key) { var obj = GetBool(dict, key); return(obj ?? false); }
public static DateTime GetDateTime2(this StrObjDict dict, string key) { var obj = GetDateTime(dict, key); return(obj ?? DateTime.MinValue); }
public static decimal GetDecimal2(this StrObjDict dict, string key) { var obj = GetDecimal(dict, key); return(obj ?? 0); }
public static double GetDouble2(this StrObjDict dict, string key) { var obj = GetDouble(dict, key); return(obj ?? 0); }
public static int GetInt2(this StrObjDict dict, string key) { var obj = GetInt(dict, key); return(obj ?? 0); }