2019-12-08 00:51:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2020-05-29 00:33:49 +08:00
|
|
|
|
namespace AntDesign
|
2019-12-08 00:51:07 +08:00
|
|
|
|
{
|
|
|
|
|
public class ClassMapper
|
|
|
|
|
{
|
|
|
|
|
public string Class => AsString();
|
|
|
|
|
|
2019-12-20 00:20:53 +08:00
|
|
|
|
internal string OriginalClass { get; set; }
|
|
|
|
|
|
2019-12-08 00:51:07 +08:00
|
|
|
|
public string AsString()
|
|
|
|
|
{
|
2020-05-10 15:42:02 +08:00
|
|
|
|
return string.Join(" ", _map.Where(i => i.Value()).Select(i => i.Key()));
|
2019-12-08 00:51:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return AsString();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-10 15:42:02 +08:00
|
|
|
|
private readonly Dictionary<Func<string>, Func<bool>> _map = new Dictionary<Func<string>, Func<bool>>();
|
2019-12-08 00:51:07 +08:00
|
|
|
|
|
|
|
|
|
public ClassMapper Add(string name)
|
|
|
|
|
{
|
2020-05-10 15:42:02 +08:00
|
|
|
|
_map.Add(() => name, () => true);
|
2019-12-08 00:51:07 +08:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ClassMapper Get(Func<string> funcName)
|
|
|
|
|
{
|
2020-05-10 15:42:02 +08:00
|
|
|
|
_map.Add(funcName, () => true);
|
2019-12-08 00:51:07 +08:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ClassMapper GetIf(Func<string> funcName, Func<bool> func)
|
|
|
|
|
{
|
2020-05-10 15:42:02 +08:00
|
|
|
|
_map.Add(funcName, func);
|
2019-12-08 00:51:07 +08:00
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ClassMapper If(string name, Func<bool> func)
|
|
|
|
|
{
|
2020-05-10 15:42:02 +08:00
|
|
|
|
_map.Add(() => name, func);
|
2019-12-08 00:51:07 +08:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2019-12-09 23:42:25 +08:00
|
|
|
|
|
|
|
|
|
public ClassMapper Clear()
|
|
|
|
|
{
|
2020-05-10 15:42:02 +08:00
|
|
|
|
_map.Clear();
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2020-05-10 15:42:02 +08:00
|
|
|
|
_map.Add(() => OriginalClass, () => !string.IsNullOrEmpty(OriginalClass));
|
2019-12-20 00:20:53 +08:00
|
|
|
|
|
2019-12-09 23:42:25 +08:00
|
|
|
|
return this;
|
|
|
|
|
}
|
2019-12-08 00:51:07 +08:00
|
|
|
|
}
|
2020-05-10 15:42:02 +08:00
|
|
|
|
}
|