ant-design-blazor/components/core/Helpers/ClassBuilderRuleDictionary.cs

31 lines
720 B
C#
Raw Normal View History

2019-12-08 00:51:07 +08:00
using System;
using System.Collections.Generic;
namespace AntDesign
2019-12-08 00:51:07 +08:00
{
public class ClassBuilderRuleDictionary<T, TK> : ClassBuilderRule<T>
{
public IDictionary<TK, string> Dictionary { get; set; }
public Func<T, TK> Func { get; set; }
public ClassBuilderRuleDictionary(Func<T, TK> func, IDictionary<TK, string> dictionary)
{
Func = func;
Dictionary = dictionary;
}
public override string GetClass(T data)
{
var key = Func(data);
string value;
if (Dictionary.TryGetValue(key, out value))
{
return value;
}
return null;
}
}
}