using Dapper;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Kean.Infrastructure.Database
{
///
/// Sql 参数
/// 继承于 Dapper.DynamicParameters 并隐藏 templates 相关;实现 IEnumerable 接口
///
public sealed class Parameters : DynamicParameters, IEnumerable>
{
///
/// 覆盖基类方法
/// "Append a whole object full of params to the dynamic"
///
public new void AddDynamicParams(object param)
{
if (param != null)
{
if (param is IEnumerable> ie)
{
foreach (var item in ie)
{
Add(item.Key, item.Value);
}
}
else
{
foreach (var item in param.GetType().GetProperties())
{
Add(item.Name, item.GetValue(param));
}
}
}
}
///
/// 返回循环访问集合的枚举数
///
public IEnumerator> GetEnumerator()
{
return ParameterNames.Select(i => new KeyValuePair(i, Get