Files
serein-flow/Library/FlowNode/FlipflopContext.cs
fengjiayi 152077e9b5 1. 重新设计了Generate项目及相关特性的命名,避免与其他类型混淆。
2. 补充了部分注释。
3. 修改了删除容器节点时,容器内子节点未正确删除的问题。
2025-07-30 21:15:07 +08:00

116 lines
3.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Serein.Library.Api;
using Serein.Library.Utils;
using System;
using System.Threading.Tasks;
namespace Serein.Library
{
/// <summary>
/// FlipflopFunc 类提供了与 Flipflop 相关的功能方法。
/// </summary>
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];
if (innerType.IsGenericType && type.GetGenericTypeDefinition() == typeof(IFlipflopContext<>))
{
var flipflop = type.GetGenericArguments()[0];
return true;
}
// 判断 innerType 是否继承 IFlipflopContext
//if (typeof(IFlipflopContext).IsAssignableFrom(innerType))
//{
// return true;
//}
//else
//{
// return false;
//}
// 检查泛型参数是否为 Flipflop<>
//if (innerType == typeof(IFlipflopContext))
//if (innerType.IsGenericType && innerType.GetGenericTypeDefinition() == typeof(FlipflopContext<>))
//{
//return true;
//}
}
return false;
}
}
/// <summary>
/// 触发器上下文
/// </summary>
public class FlipflopContext<TResult> : IFlipflopContext<TResult>
{
/// <summary>
/// 触发器完成的状态(根据业务场景手动设置)
/// </summary>
public FlipflopStateType State { get; set; }
/// <summary>
/// 触发类型
/// </summary>
public TriggerDescription Type { get; set; }
/// <summary>
/// 触发时传递的数据
/// </summary>
public TResult Value { get; set; }
/// <summary>
/// 触发器上下文构造函数
/// </summary>
/// <param name="ffState"></param>
public FlipflopContext(FlipflopStateType ffState)
{
State = ffState;
}
/// <summary>
/// 触发器上下文构造函数,传入状态和数据值
/// </summary>
/// <param name="ffState"></param>
/// <param name="value"></param>
public FlipflopContext(FlipflopStateType ffState, TResult value)
{
State = ffState;
Value = value;
}
}
}