ant-design-blazor/components/core/Helpers/ClassBuilderRuleDictionary.cs
2020-05-29 00:33:49 +08:00

31 lines
720 B
C#

using System;
using System.Collections.Generic;
namespace AntDesign
{
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;
}
}
}