mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-20 00:06:45 +08:00
上传了新的示例工程
This commit is contained in:
@@ -26,7 +26,7 @@ namespace Serein.Library.Entity
|
||||
///// <summary>
|
||||
///// 显式类型
|
||||
///// </summary>
|
||||
//public Type ExplicitType { get; set; }
|
||||
public Type ExplicitType { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 显示类型编号>
|
||||
@@ -55,7 +55,7 @@ namespace Serein.Library.Entity
|
||||
{
|
||||
Index = Index,
|
||||
IsExplicitData = IsExplicitData,
|
||||
// ExplicitType = ExplicitType,
|
||||
ExplicitType = ExplicitType,
|
||||
ExplicitTypeName = ExplicitTypeName,
|
||||
DataType = DataType,
|
||||
ParameterName = ParameterName,
|
||||
|
||||
@@ -73,6 +73,30 @@ namespace Serein.Library.Attributes
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 枚举值转换器,要求枚举项标记的BindValueAttribute特性,与搭配的参数类型一致,否则参数不会传入
|
||||
/// </summary>
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
public class EnumTypeConvertorAttribute : Attribute
|
||||
{
|
||||
public Type EnumType { get; }
|
||||
|
||||
public EnumTypeConvertorAttribute(Type @enum)
|
||||
{
|
||||
if (@enum.IsEnum)
|
||||
{
|
||||
EnumType = @enum;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("需要枚举类型");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class PLCValueAttribute : Attribute
|
||||
{
|
||||
@@ -121,27 +145,4 @@ namespace Serein.Library.Attributes
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 枚举值转换器
|
||||
/// </summary>
|
||||
|
||||
//[AttributeUsage(AttributeTargets.Parameter)]
|
||||
//public class EnumConvertorAttribute : Attribute
|
||||
//{
|
||||
// public Type Enum { get; }
|
||||
|
||||
// public EnumConvertorAttribute(Type @enum)
|
||||
// {
|
||||
// if (@enum.IsEnum)
|
||||
// {
|
||||
// Enum = @enum;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// throw new ArgumentException("需要枚举类型");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,13 @@ namespace Serein.Library.Utils
|
||||
|
||||
return attribute != null ? (TResult)valueSelector(attribute) : default;
|
||||
}
|
||||
public static object GetBoundValue(Type enumType,object enumValue, Func<BindValueAttribute, object> valueSelector)
|
||||
{
|
||||
var fieldInfo = enumType.GetField(enumValue.ToString());
|
||||
var attribute = fieldInfo.GetCustomAttribute<BindValueAttribute>();
|
||||
|
||||
return attribute != null ? valueSelector(attribute) : default;
|
||||
}
|
||||
|
||||
//public static TResult GetBoundValue<TEnum, TAttribute, TResult>(TEnum enumValue,
|
||||
// Func<TAttribute, TResult> valueSelector)
|
||||
|
||||
Reference in New Issue
Block a user