Files
“wanyongkang” ed3b2c653e 接口文件
2024-04-10 13:55:27 +08:00

74 lines
1.6 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
namespace Alipay.AopSdk.Core
{
/// <summary>
/// 符合AOP习惯的纯字符串字典结构。
/// </summary>
public class AopDictionary : Dictionary<string, string>
{
private const string DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public AopDictionary()
{
}
public AopDictionary(IDictionary<string, string> dictionary)
: base(dictionary)
{
}
/// <summary>
/// 添加一个新的键值对。空键或者空值的键值对将会被忽略。
/// </summary>
/// <param name="key">键名称</param>
/// <param name="value">键对应的值目前支持string, int, long, double, bool, DateTime类型</param>
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 DateTime?)
{
var dateTime = value as DateTime?;
strValue = dateTime.Value.ToString(DATE_TIME_FORMAT);
}
else if (value is int?)
{
strValue = (value as int?).Value.ToString();
}
else if (value is long?)
{
strValue = (value as long?).Value.ToString();
}
else if (value is double?)
{
strValue = (value as double?).Value.ToString();
}
else if (value is bool?)
{
strValue = (value as bool?).Value.ToString().ToLower();
}
else
{
strValue = value.ToString();
}
Add(key, strValue);
}
public new void Add(string key, string value)
{
if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
base.Add(key, value);
}
}
}