mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-04-05 07:46:35 +08:00
优化了示例工程
This commit is contained in:
@@ -20,9 +20,9 @@ namespace Serein.Library.Entity
|
||||
/// </summary>
|
||||
public bool IsExplicitData { get; set; }
|
||||
/// <summary>
|
||||
/// 是否为值转换器
|
||||
/// 转换器 IEnumConvertor<,>
|
||||
/// </summary>
|
||||
public bool IsEnumConvertor { get; set; }
|
||||
public Func<object, object> Convertor { get; set; }
|
||||
///// <summary>
|
||||
///// 显式类型
|
||||
///// </summary>
|
||||
@@ -57,6 +57,7 @@ namespace Serein.Library.Entity
|
||||
IsExplicitData = IsExplicitData,
|
||||
ExplicitType = ExplicitType,
|
||||
ExplicitTypeName = ExplicitTypeName,
|
||||
Convertor = Convertor,
|
||||
DataType = DataType,
|
||||
ParameterName = ParameterName,
|
||||
DataValue = string.IsNullOrEmpty(DataValue) ? string.Empty : DataValue,
|
||||
|
||||
@@ -7,11 +7,13 @@ namespace Serein.Library.Entity
|
||||
{
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 每个节点有独自的MethodDetails实例
|
||||
/// </summary>
|
||||
public class MethodDetails
|
||||
{
|
||||
/// <summary>
|
||||
/// 拷贝
|
||||
/// 从DLL拖动出来时拷贝新的实例
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public MethodDetails Clone()
|
||||
@@ -37,7 +39,7 @@ namespace Serein.Library.Entity
|
||||
/// <summary>
|
||||
/// 是否保护参数
|
||||
/// </summary>
|
||||
public bool IsProtectionParameter { get; set; } = false;
|
||||
public bool IsProtectionParameter { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 作用实例的类型
|
||||
|
||||
@@ -9,6 +9,14 @@ namespace Serein.Library.Attributes
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public sealed class AutoInjectionAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表示该类自动注册
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public sealed class AutoRegisterAttribute : Attribute
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,54 +103,30 @@ namespace Serein.Library.Attributes
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class PLCValueAttribute : Attribute
|
||||
/// <summary>
|
||||
/// 绑定转换器
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
public class BindConvertorAttribute : Attribute
|
||||
{
|
||||
public enum VarType
|
||||
public Type EnumType { get; }
|
||||
public Type ConvertorType { get; }
|
||||
|
||||
public BindConvertorAttribute(Type @enum, Type convertor)
|
||||
{
|
||||
/// <summary>
|
||||
/// 可写入值
|
||||
/// </summary>
|
||||
Write,
|
||||
/// <summary>
|
||||
/// 定时读取的可写入值(用来写入前判断),应该几乎不会有这种类型?
|
||||
/// </summary>
|
||||
TimingReadOrWrite,
|
||||
/// <summary>
|
||||
/// 只读取值(使用时刷新)
|
||||
/// </summary>
|
||||
ReadOnly,
|
||||
/// <summary>
|
||||
/// 定时刷新的只读取值(定时刷新用来触发触发器)
|
||||
/// </summary>
|
||||
TimingReadOnly,
|
||||
}
|
||||
|
||||
public bool IsProtected { get; }
|
||||
public Type DataType { get; }
|
||||
public string Var { get; }
|
||||
//public int Length { get; }
|
||||
//public double Offset { get; }
|
||||
public VarType Type { get; }
|
||||
//public int RefreshInterval { get; }
|
||||
|
||||
|
||||
|
||||
public PLCValueAttribute(Type type,
|
||||
string @var,
|
||||
VarType varType
|
||||
//int refreshInterval = 100
|
||||
)
|
||||
{
|
||||
DataType = type;
|
||||
Var = @var;
|
||||
//Offset = offset;
|
||||
//RefreshInterval = refreshInterval;
|
||||
Type = varType;
|
||||
//Length = length;
|
||||
this.EnumType = @enum;
|
||||
this.ConvertorType = convertor;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 枚举转换器接口
|
||||
/// </summary>
|
||||
/// <typeparam name="TEnum"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
public interface IEnumConvertor<TEnum, TValue>
|
||||
{
|
||||
TValue Convertor(TEnum e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,16 +24,16 @@ namespace Serein.Library.Utils
|
||||
return attribute != null ? 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>();
|
||||
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;
|
||||
//}
|
||||
return attribute != null ? valueSelector(attribute) : default;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user