Files
serein-flow/Library/NodeAttribute.cs

133 lines
3.3 KiB
C#
Raw Normal View History

using Serein.Library.Enums;
using System;
namespace Serein.Library.Attributes
{
/// <summary>
/// 表示该属性为自动注入依赖项
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
public sealed class AutoInjectionAttribute : Attribute
{
}
2024-09-28 23:55:19 +08:00
/// <summary>
/// 表示该类自动注册(单例模式)
2024-09-28 23:55:19 +08:00
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public sealed class AutoRegisterAttribute : Attribute
{
}
/// <summary>
/// 用来判断一个类是否需要注册并构建节点
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class DynamicFlowAttribute : Attribute
{
public DynamicFlowAttribute(bool scan = true)
{
Scan = scan;
}
public bool Scan { get; set; } = true;
}
/// <summary>
2024-09-15 22:07:10 +08:00
/// 建议触发器手动设置返回类型
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class NodeActionAttribute : Attribute
{
public NodeActionAttribute(NodeType methodDynamicType,
string methodTips = "",
bool scan = true,
string lockName = "")
{
Scan = scan;
MethodDynamicType = methodDynamicType;
MethodTips = methodTips;
LockName = lockName;
}
public bool Scan;
public string MethodTips;
public NodeType MethodDynamicType;
public Type ReturnType;
public string LockName;
}
2024-09-25 22:20:23 +08:00
//[AttributeUsage(AttributeTargets.Field)]
//public class BindTypeAttribute : Attribute
//{
// public Type Type { get; }
// public BindTypeAttribute(Type type)
// {
// Type = type;
// }
//}
[AttributeUsage(AttributeTargets.Field)]
public class BindValueAttribute : Attribute
{
public object Value { get; }
public BindValueAttribute(object value)
{
Value = value;
}
}
2024-09-27 10:30:19 +08:00
/// <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("需要枚举类型");
}
}
}
2024-09-28 23:55:19 +08:00
/// <summary>
/// 绑定转换器
/// </summary>
[AttributeUsage(AttributeTargets.Parameter)]
public class BindConvertorAttribute : Attribute
2024-09-25 22:20:23 +08:00
{
2024-09-28 23:55:19 +08:00
public Type EnumType { get; }
public Type ConvertorType { get; }
2024-09-25 22:20:23 +08:00
2024-09-28 23:55:19 +08:00
public BindConvertorAttribute(Type @enum, Type convertor)
2024-09-25 22:20:23 +08:00
{
2024-09-28 23:55:19 +08:00
this.EnumType = @enum;
this.ConvertorType = convertor;
2024-09-25 22:20:23 +08:00
}
}
2024-09-28 23:55:19 +08:00
/// <summary>
/// 枚举转换器接口
/// </summary>
/// <typeparam name="TEnum"></typeparam>
/// <typeparam name="TValue"></typeparam>
public interface IEnumConvertor<TEnum, TValue>
{
TValue Convertor(TEnum e);
}
}