mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
先想到这吧
This commit is contained in:
35
Library/Utils/EnumHelper.cs
Normal file
35
Library/Utils/EnumHelper.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Serein.Library.Attributes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace Serein.Library.Utils
|
||||
{
|
||||
public static class EnumHelper
|
||||
{
|
||||
public static TResult GetBoundValue<TEnum, TResult>(TEnum enumValue, Func<BindValueAttribute, object> valueSelector)
|
||||
where TEnum : Enum
|
||||
{
|
||||
var fieldInfo = typeof(TEnum).GetField(enumValue.ToString());
|
||||
var attribute = fieldInfo.GetCustomAttribute<BindValueAttribute>();
|
||||
|
||||
return attribute != null ? (TResult)valueSelector(attribute) : default;
|
||||
}
|
||||
|
||||
//public static TResult GetBoundValue<TEnum, TAttribute, TResult>(TEnum enumValue,
|
||||
// Func<TAttribute, TResult> valueSelector)
|
||||
// where TEnum : Enum
|
||||
// where TAttribute : Attribute
|
||||
//{
|
||||
// var fieldInfo = typeof(TEnum).GetField(enumValue.ToString());
|
||||
// var attribute = fieldInfo.GetCustomAttribute<TAttribute>();
|
||||
|
||||
// return attribute != null ? valueSelector(attribute) : default;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user