using System;
using System.Collections.Generic;
namespace Top.Api
{
///
/// 符合TOP习惯的纯字符串字典结构。
///
public class TopDictionary : Dictionary
{
public TopDictionary() { }
public TopDictionary(IDictionary dictionary)
: base(dictionary)
{ }
///
/// 添加一个新的键值对。空键或者空值的键值对将会被忽略。
///
/// 键名称
/// 键对应的值,目前支持:string, int, long, double, bool, DateTime类型
public void Add(string key, object value)
{
string strValue;
if (value == null)
{
strValue = null;
}
else if (value is string)
{
strValue = (string)value;
}
else if (value is Nullable)
{
Nullable dateTime = value as Nullable;
strValue = dateTime.Value.ToString(Constants.DATE_TIME_FORMAT);
}
else if (value is Nullable)
{
strValue = (value as Nullable).Value.ToString();
}
else if (value is Nullable)
{
strValue = (value as Nullable).Value.ToString();
}
else if (value is Nullable)
{
strValue = (value as Nullable).Value.ToString();
}
else if (value is Nullable)
{
strValue = (value as Nullable).Value.ToString().ToLower();
}
else
{
strValue = value.ToString();
}
this.Add(key, strValue);
}
public new void Add(string key, string value)
{
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
{
base[key] = value;
}
}
public void AddAll(IDictionary dict)
{
if (dict != null && dict.Count > 0)
{
IEnumerator> kvps = dict.GetEnumerator();
while (kvps.MoveNext())
{
KeyValuePair kvp = kvps.Current;
Add(kvp.Key, kvp.Value);
}
}
}
}
}