上传了新的示例工程

This commit is contained in:
fengjiayi
2024-09-27 10:30:19 +08:00
parent 54c35ce445
commit f3a90df452
24 changed files with 1062 additions and 127 deletions

View File

@@ -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,

View File

@@ -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("需要枚举类型");
// }
// }
//}
}

View File

@@ -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)