2024-09-12 20:32:54 +08:00
|
|
|
|
using Serein.Library.Api;
|
2024-12-26 16:42:05 +08:00
|
|
|
|
using Serein.Library.Utils;
|
2024-09-12 20:32:54 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Serein.Library.Framework.NodeFlow
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class FlipflopFunc
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 传入触发器方法的返回类型,尝试获取Task[Flipflop[]] 中的泛型类型
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
//public static Type GetFlipflopInnerType(Type type)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// // 检查是否为泛型类型且为 Task<>
|
|
|
|
|
|
// if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Task<>))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// // 获取 Task<> 的泛型参数类型,即 Flipflop<>
|
|
|
|
|
|
// var innerType = type.GetGenericArguments()[0];
|
|
|
|
|
|
|
|
|
|
|
|
// // 检查泛型参数是否为 Flipflop<>
|
|
|
|
|
|
// if (innerType.IsGenericType && innerType.GetGenericTypeDefinition() == typeof(FlipflopContext<>))
|
|
|
|
|
|
// {
|
|
|
|
|
|
// // 获取 Flipflop<> 的泛型参数类型,即 T
|
|
|
|
|
|
// var flipflopInnerType = innerType.GetGenericArguments()[0];
|
|
|
|
|
|
|
|
|
|
|
|
// // 返回 Flipflop<> 中的具体类型
|
|
|
|
|
|
// return flipflopInnerType;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
// // 如果不符合条件,返回 null
|
|
|
|
|
|
// return null;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool IsTaskOfFlipflop(Type type)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 检查是否为泛型类型且为 Task<>
|
|
|
|
|
|
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Task<>))
|
|
|
|
|
|
{
|
|
|
|
|
|
// 获取 Task<> 的泛型参数类型
|
|
|
|
|
|
var innerType = type.GetGenericArguments()[0];
|
2024-10-11 16:46:16 +08:00
|
|
|
|
if (innerType.IsGenericType && type.GetGenericTypeDefinition() == typeof(IFlipflopContext<>))
|
2024-09-12 20:32:54 +08:00
|
|
|
|
{
|
2024-10-11 16:46:16 +08:00
|
|
|
|
var flipflop = type.GetGenericArguments()[0];
|
2024-09-12 20:32:54 +08:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-10-11 16:46:16 +08:00
|
|
|
|
|
|
|
|
|
|
//// 检查泛型参数是否为 Flipflop<>
|
|
|
|
|
|
//if (innerType == typeof(FlipflopContext))
|
|
|
|
|
|
////if (innerType.IsGenericType && innerType.GetGenericTypeDefinition() == typeof(FlipflopContext<>))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
//}
|
2024-09-12 20:32:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 触发器上下文
|
|
|
|
|
|
/// </summary>
|
2024-10-11 16:46:16 +08:00
|
|
|
|
public class FlipflopContext<TResult> : IFlipflopContext<TResult>
|
2024-09-12 20:32:54 +08:00
|
|
|
|
{
|
2024-09-15 22:07:10 +08:00
|
|
|
|
public FlipflopStateType State { get; set; }
|
2024-10-11 16:46:16 +08:00
|
|
|
|
|
2024-12-23 23:19:10 +08:00
|
|
|
|
public TriggerDescription Type { get; set; }
|
2024-10-11 16:46:16 +08:00
|
|
|
|
public TResult Value { get; set; }
|
2024-09-20 17:11:31 +08:00
|
|
|
|
|
2024-09-15 22:07:10 +08:00
|
|
|
|
public FlipflopContext(FlipflopStateType ffState)
|
2024-09-12 20:32:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
State = ffState;
|
|
|
|
|
|
}
|
2024-10-11 16:46:16 +08:00
|
|
|
|
|
|
|
|
|
|
public FlipflopContext(FlipflopStateType ffState, TResult value)
|
2024-09-12 20:32:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
State = ffState;
|
2024-10-11 16:46:16 +08:00
|
|
|
|
Value = value;
|
2024-09-12 20:32:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-09-15 22:07:10 +08:00
|
|
|
|
|
2024-09-12 20:32:54 +08:00
|
|
|
|
}
|