mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-03 00:00:49 +08:00
移除了文件
This commit is contained in:
@@ -1,222 +0,0 @@
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Entity;
|
||||
using Serein.Library.Enums;
|
||||
|
||||
namespace Serein.NodeFlow.Base
|
||||
{
|
||||
/// <summary>
|
||||
/// 节点基类(数据):条件控件,动作控件,条件区域,动作区域
|
||||
/// </summary>
|
||||
public abstract partial class NodeModelBase : IDynamicFlowNode
|
||||
{
|
||||
|
||||
public NodeModelBase()
|
||||
{
|
||||
PreviousNodes = [];
|
||||
SuccessorNodes = [];
|
||||
foreach (ConnectionType ctType in NodeStaticConfig.ConnectionTypes)
|
||||
{
|
||||
PreviousNodes[ctType] = [];
|
||||
SuccessorNodes[ctType] = [];
|
||||
}
|
||||
DebugSetting = new NodeDebugSetting();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 调试功能
|
||||
/// </summary>
|
||||
public NodeDebugSetting DebugSetting { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点对应的控件类型
|
||||
/// </summary>
|
||||
public NodeControlType ControlType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 方法描述,对应DLL的方法
|
||||
/// </summary>
|
||||
public MethodDetails MethodDetails { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 节点guid
|
||||
/// </summary>
|
||||
public string Guid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 显示名称
|
||||
/// </summary>
|
||||
public string DisplayName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 是否为起点控件
|
||||
/// </summary>
|
||||
public bool IsStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 运行时的上一节点
|
||||
/// </summary>
|
||||
public NodeModelBase? PreviousNode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 不同分支的父节点
|
||||
/// </summary>
|
||||
public Dictionary<ConnectionType,List<NodeModelBase>> PreviousNodes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 不同分支的子节点
|
||||
/// </summary>
|
||||
public Dictionary<ConnectionType,List<NodeModelBase>> SuccessorNodes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前节点执行完毕后需要执行的下一个分支的类别
|
||||
/// </summary>
|
||||
public ConnectionType NextOrientation { get; set; } = ConnectionType.None;
|
||||
|
||||
/// <summary>
|
||||
/// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值)
|
||||
/// </summary>
|
||||
public Exception? RuningException { get; set; } = null;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 控制FlowData在同一时间只会被同一个线程更改。
|
||||
/// </summary>
|
||||
private readonly ReaderWriterLockSlim _flowDataLock = new ReaderWriterLockSlim();
|
||||
private object? _flowData;
|
||||
/// <summary>
|
||||
/// 当前传递数据(执行了节点对应的方法,才会存在值)。
|
||||
/// </summary>
|
||||
protected object? FlowData
|
||||
{
|
||||
get
|
||||
{
|
||||
_flowDataLock.EnterReadLock();
|
||||
try
|
||||
{
|
||||
return _flowData;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_flowDataLock.ExitReadLock();
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
_flowDataLock.EnterWriteLock();
|
||||
try
|
||||
{
|
||||
_flowData = value;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_flowDataLock.ExitWriteLock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 节点基类(数据):条件控件,动作控件,条件区域,动作区域
|
||||
/// </summary>
|
||||
//public class NodeModelBaseBuilder
|
||||
//{
|
||||
// public NodeModelBaseBuilder(NodeModelBase builder)
|
||||
// {
|
||||
// this.ControlType = builder.ControlType;
|
||||
// this.MethodDetails = builder.MethodDetails;
|
||||
// this.Guid = builder.Guid;
|
||||
// this.DisplayName = builder.DisplayName;
|
||||
// this.IsStart = builder.IsStart;
|
||||
// this.PreviousNode = builder.PreviousNode;
|
||||
// this.PreviousNodes = builder.PreviousNodes;
|
||||
// this.SucceedBranch = builder.SucceedBranch;
|
||||
// this.FailBranch = builder.FailBranch;
|
||||
// this.ErrorBranch = builder.ErrorBranch;
|
||||
// this.UpstreamBranch = builder.UpstreamBranch;
|
||||
// this.FlowState = builder.FlowState;
|
||||
// this.RuningException = builder.RuningException;
|
||||
// this.FlowData = builder.FlowData;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// /// <summary>
|
||||
// /// 节点对应的控件类型
|
||||
// /// </summary>
|
||||
// public NodeControlType ControlType { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 方法描述,对应DLL的方法
|
||||
// /// </summary>
|
||||
// public MethodDetails MethodDetails { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 节点guid
|
||||
// /// </summary>
|
||||
// public string Guid { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 显示名称
|
||||
// /// </summary>
|
||||
// public string DisplayName { get;}
|
||||
|
||||
// /// <summary>
|
||||
// /// 是否为起点控件
|
||||
// /// </summary>
|
||||
// public bool IsStart { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 运行时的上一节点
|
||||
// /// </summary>
|
||||
// public NodeModelBase? PreviousNode { get; }
|
||||
|
||||
// /// <summary>
|
||||
// /// 上一节点集合
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> PreviousNodes { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 下一节点集合(真分支)
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> SucceedBranch { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 下一节点集合(假分支)
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> FailBranch { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 异常分支
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> ErrorBranch { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 上游分支
|
||||
// /// </summary>
|
||||
// public List<NodeModelBase> UpstreamBranch { get; } = [];
|
||||
|
||||
// /// <summary>
|
||||
// /// 当前执行状态(进入真分支还是假分支,异常分支在异常中确定)
|
||||
// /// </summary>
|
||||
// public FlowStateType FlowState { get; set; } = FlowStateType.None;
|
||||
|
||||
// /// <summary>
|
||||
// /// 运行时的异常信息(仅在 FlowState 为 Error 时存在对应值)
|
||||
// /// </summary>
|
||||
// public Exception RuningException { get; set; } = null;
|
||||
|
||||
// /// <summary>
|
||||
// /// 当前传递数据(执行了节点对应的方法,才会存在值)
|
||||
// /// </summary>
|
||||
// public object? FlowData { get; set; } = null;
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,457 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Attributes;
|
||||
using Serein.Library.Entity;
|
||||
using Serein.Library.Enums;
|
||||
using Serein.Library.Ex;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Tool;
|
||||
using Serein.NodeFlow.Tool.SereinExpression;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using static Serein.Library.Utils.ChannelFlowInterrupt;
|
||||
|
||||
namespace Serein.NodeFlow.Base
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 节点基类(数据):条件控件,动作控件,条件区域,动作区域
|
||||
/// </summary>
|
||||
public abstract partial class NodeModelBase : IDynamicFlowNode
|
||||
{
|
||||
|
||||
|
||||
#region 调试中断
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 不再中断
|
||||
/// </summary>
|
||||
public void CancelInterrupt()
|
||||
{
|
||||
this.DebugSetting.InterruptClass = InterruptClass.None;
|
||||
DebugSetting.CancelInterruptCallback?.Invoke();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 导出/导入项目文件节点信息
|
||||
|
||||
internal abstract Parameterdata[] GetParameterdatas();
|
||||
public virtual NodeInfo ToInfo()
|
||||
{
|
||||
// if (MethodDetails == null) return null;
|
||||
|
||||
var trueNodes = SuccessorNodes[ConnectionType.IsSucceed].Select(item => item.Guid); // 真分支
|
||||
var falseNodes = SuccessorNodes[ConnectionType.IsFail].Select(item => item.Guid);// 假分支
|
||||
var errorNodes = SuccessorNodes[ConnectionType.IsError].Select(item => item.Guid);// 异常分支
|
||||
var upstreamNodes = SuccessorNodes[ConnectionType.Upstream].Select(item => item.Guid);// 上游分支
|
||||
|
||||
// 生成参数列表
|
||||
Parameterdata[] parameterData = GetParameterdatas();
|
||||
|
||||
return new NodeInfo
|
||||
{
|
||||
Guid = Guid,
|
||||
MethodName = MethodDetails?.MethodName,
|
||||
Label = DisplayName ?? "",
|
||||
Type = this.GetType().ToString(),
|
||||
TrueNodes = trueNodes.ToArray(),
|
||||
FalseNodes = falseNodes.ToArray(),
|
||||
UpstreamNodes = upstreamNodes.ToArray(),
|
||||
ParameterData = parameterData.ToArray(),
|
||||
ErrorNodes = errorNodes.ToArray(),
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
public virtual NodeModelBase LoadInfo(NodeInfo nodeInfo)
|
||||
{
|
||||
this.Guid = nodeInfo.Guid;
|
||||
if (this.MethodDetails is not null)
|
||||
{
|
||||
for (int i = 0; i < nodeInfo.ParameterData.Length; i++)
|
||||
{
|
||||
Parameterdata? pd = nodeInfo.ParameterData[i];
|
||||
this.MethodDetails.ParameterDetailss[i].IsExplicitData = pd.State;
|
||||
this.MethodDetails.ParameterDetailss[i].DataValue = pd.Value;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 节点方法的执行
|
||||
|
||||
/// <summary>
|
||||
/// 是否应该退出执行
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="flowCts"></param>
|
||||
/// <returns></returns>
|
||||
public static bool IsBradk(IDynamicContext context, CancellationTokenSource? flowCts)
|
||||
{
|
||||
// 上下文不再执行
|
||||
if(context.RunState == RunState.Completion)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// 不存在全局触发器时,流程运行状态被设置为完成,退出执行,用于打断无限循环分支。
|
||||
if (flowCts is null && context.Env.FlowState == RunState.Completion)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// 如果存在全局触发器,且触发器的执行任务已经被取消时,退出执行。
|
||||
if (flowCts is not null)
|
||||
{
|
||||
if (flowCts.IsCancellationRequested)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 开始执行
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public async Task StartFlowAsync(IDynamicContext context)
|
||||
{
|
||||
Stack<NodeModelBase> stack = new Stack<NodeModelBase>();
|
||||
stack.Push(this);
|
||||
var flowCts = context.Env.IOC.Get<CancellationTokenSource>(FlowStarter.FlipFlopCtsName);
|
||||
bool hasFlipflow = flowCts != null;
|
||||
while (stack.Count > 0) // 循环中直到栈为空才会退出循环
|
||||
{
|
||||
await Task.Delay(0);
|
||||
// 从栈中弹出一个节点作为当前节点进行处理
|
||||
var currentNode = stack.Pop();
|
||||
|
||||
#region 执行相关
|
||||
|
||||
// 筛选出上游分支
|
||||
var upstreamNodes = currentNode.SuccessorNodes[ConnectionType.Upstream].ToArray();
|
||||
for (int index = 0; index < upstreamNodes.Length; index++)
|
||||
{
|
||||
NodeModelBase? upstreamNode = upstreamNodes[index];
|
||||
if (upstreamNode is not null && upstreamNode.DebugSetting.IsEnable)
|
||||
{
|
||||
if (upstreamNode.DebugSetting.InterruptClass != InterruptClass.None) // 执行触发前
|
||||
{
|
||||
var cancelType = await upstreamNode.DebugSetting.GetInterruptTask();
|
||||
await Console.Out.WriteLineAsync($"[{upstreamNode.MethodDetails?.MethodName}]中断已{cancelType},开始执行后继分支");
|
||||
}
|
||||
upstreamNode.PreviousNode = currentNode;
|
||||
await upstreamNode.StartFlowAsync(context); // 执行流程节点的上游分支
|
||||
if (upstreamNode.NextOrientation == ConnectionType.IsError)
|
||||
{
|
||||
// 如果上游分支执行失败,不再继续执行
|
||||
// 使上游节点(仅上游节点本身,不包含上游节点的后继节点)
|
||||
// 具备通过抛出异常中断流程的能力
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IsBradk(context, flowCts)) break; // 退出执行
|
||||
// 上游分支执行完成,才执行当前节点
|
||||
object? newFlowData = await currentNode.ExecutingAsync(context);
|
||||
if (IsBradk(context, flowCts)) break; // 退出执行
|
||||
|
||||
await RefreshFlowDataAndExpInterrupt(context, currentNode, newFlowData); // 执行当前节点后刷新数据
|
||||
#endregion
|
||||
|
||||
|
||||
#region 执行完成
|
||||
|
||||
// 选择后继分支
|
||||
var nextNodes = currentNode.SuccessorNodes[currentNode.NextOrientation];
|
||||
|
||||
// 将下一个节点集合中的所有节点逆序推入栈中
|
||||
for (int i = nextNodes.Count - 1; i >= 0; i--)
|
||||
{
|
||||
// 筛选出启用的节点的节点
|
||||
if (nextNodes[i].DebugSetting.IsEnable)
|
||||
{
|
||||
nextNodes[i].PreviousNode = currentNode;
|
||||
stack.Push(nextNodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 执行节点对应的方法
|
||||
/// </summary>
|
||||
/// <param name="context">流程上下文</param>
|
||||
/// <returns>节点传回数据对象</returns>
|
||||
public virtual async Task<object?> ExecutingAsync(IDynamicContext context)
|
||||
{
|
||||
#region 调试中断
|
||||
|
||||
if (DebugSetting.InterruptClass != InterruptClass.None) // 执行触发检查是否需要中断
|
||||
{
|
||||
var cancelType = await this.DebugSetting.GetInterruptTask(); // 等待中断结束
|
||||
await Console.Out.WriteLineAsync($"[{this.MethodDetails?.MethodName}]中断已{cancelType},开始执行后继分支");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
MethodDetails? md = MethodDetails;
|
||||
//var del = md.MethodDelegate.Clone();
|
||||
if (md is null)
|
||||
{
|
||||
throw new Exception($"节点{this.Guid}不存在方法信息,请检查是否需要重写节点的ExecutingAsync");
|
||||
}
|
||||
if (!context.Env.TryGetDelegateDetails(md.MethodName, out var dd))
|
||||
{
|
||||
throw new Exception($"节点{this.Guid}不存在对应委托");
|
||||
}
|
||||
md.ActingInstance ??= context.Env.IOC.Get(md.ActingInstanceType);
|
||||
object instance = md.ActingInstance;
|
||||
|
||||
|
||||
object? result = null;
|
||||
|
||||
try
|
||||
{
|
||||
object?[]? args = GetParameters(context, this, md);
|
||||
result = await dd.InvokeAsync(md.ActingInstance, args);
|
||||
NextOrientation = ConnectionType.IsSucceed;
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Out.WriteLineAsync($"节点[{this.MethodDetails?.MethodName}]异常:" + ex);
|
||||
NextOrientation = ConnectionType.IsError;
|
||||
RuningException = ex;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取对应的参数数组
|
||||
/// </summary>
|
||||
public static object?[]? GetParameters(IDynamicContext context, NodeModelBase nodeModel, MethodDetails md)
|
||||
{
|
||||
// 用正确的大小初始化参数数组
|
||||
if (md.ParameterDetailss.Length == 0)
|
||||
{
|
||||
return null;// md.ActingInstance
|
||||
}
|
||||
|
||||
object?[]? parameters = new object[md.ParameterDetailss.Length];
|
||||
var flowData = nodeModel.PreviousNode?.FlowData; // 当前传递的数据
|
||||
var previousDataType = flowData?.GetType();
|
||||
|
||||
for (int i = 0; i < parameters.Length; i++)
|
||||
{
|
||||
|
||||
object? inputParameter; // 存放解析的临时参数
|
||||
var ed = md.ParameterDetailss[i]; // 方法入参描述
|
||||
|
||||
|
||||
if (ed.IsExplicitData) // 判断是否使用显示的输入参数
|
||||
{
|
||||
if (ed.DataValue.StartsWith("@get", StringComparison.OrdinalIgnoreCase) && flowData is not null)
|
||||
{
|
||||
// 执行表达式从上一节点获取对象
|
||||
inputParameter = SerinExpressionEvaluator.Evaluate(ed.DataValue, flowData, out _);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用输入的固定值
|
||||
inputParameter = ed.DataValue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
inputParameter = flowData; // 使用上一节点的对象
|
||||
}
|
||||
|
||||
// 入参存在取值转换器
|
||||
if (ed.ExplicitType.IsEnum && ed.Convertor is not null)
|
||||
{
|
||||
if (Enum.TryParse(ed.ExplicitType, ed.DataValue, out var resultEnum))
|
||||
{
|
||||
var value = ed.Convertor(resultEnum);
|
||||
if (value is not null)
|
||||
{
|
||||
parameters[i] = value;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("转换器调用失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 入参存在类型转换器,获取枚举转换器中记录的枚举
|
||||
if (ed.ExplicitType.IsEnum && ed.DataType != ed.ExplicitType)
|
||||
{
|
||||
if (Enum.TryParse(ed.ExplicitType, ed.DataValue, out var resultEnum)) // 获取对应的枚举项
|
||||
{
|
||||
// 获取绑定的类型
|
||||
var type = EnumHelper.GetBoundValue(ed.ExplicitType, resultEnum, attr => attr.Value);
|
||||
if (type is Type enumBindType && enumBindType is not null)
|
||||
{
|
||||
var value = context.Env.IOC.Instantiate(enumBindType);
|
||||
if (value is not null)
|
||||
{
|
||||
parameters[i] = value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (ed.DataType.IsValueType)
|
||||
{
|
||||
var valueStr = inputParameter?.ToString();
|
||||
parameters[i] = valueStr.ToValueData(ed.DataType);
|
||||
}
|
||||
else
|
||||
{
|
||||
var valueStr = inputParameter?.ToString();
|
||||
parameters[i] = ed.DataType switch
|
||||
{
|
||||
Type t when t == typeof(string) => valueStr,
|
||||
Type t when t == typeof(IDynamicContext) => context, // 上下文
|
||||
Type t when t == typeof(DateTime) => string.IsNullOrEmpty(valueStr) ? 0 : DateTime.Parse(valueStr),
|
||||
|
||||
Type t when t == typeof(MethodDetails) => md, // 节点方法描述
|
||||
Type t when t == typeof(NodeModelBase) => nodeModel, // 节点实体类
|
||||
|
||||
Type t when t.IsArray => (inputParameter as Array)?.Cast<object>().ToList(),
|
||||
Type t when t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>) => inputParameter,
|
||||
_ => inputParameter,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新节点数据,并检查监视表达式是否生效
|
||||
/// </summary>
|
||||
/// <param name="context">上下文</param>
|
||||
/// <param name="nodeModel">节点Moel</param>
|
||||
/// <param name="newData">新的数据</param>
|
||||
/// <returns></returns>
|
||||
public static async Task RefreshFlowDataAndExpInterrupt(IDynamicContext context, NodeModelBase nodeModel, object? newData = null)
|
||||
{
|
||||
string guid = nodeModel.Guid;
|
||||
if (newData is not null)
|
||||
{
|
||||
await MonitorObjExpInterrupt(context, nodeModel, newData, 0); // 首先监视对象
|
||||
await MonitorObjExpInterrupt(context, nodeModel, newData, 1); // 然后监视节点
|
||||
nodeModel.FlowData = newData; // 替换数据
|
||||
context.AddOrUpdate(guid, nodeModel); // 上下文中更新数据
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task MonitorObjExpInterrupt(IDynamicContext context, NodeModelBase nodeModel, object? data, int monitorType)
|
||||
{
|
||||
MonitorObjectEventArgs.ObjSourceType sourceType;
|
||||
string? key;
|
||||
if (monitorType == 0)
|
||||
{
|
||||
key = data?.GetType()?.FullName;
|
||||
sourceType = MonitorObjectEventArgs.ObjSourceType.IOCObj;
|
||||
}
|
||||
else
|
||||
{
|
||||
key = nodeModel.Guid;
|
||||
sourceType = MonitorObjectEventArgs.ObjSourceType.IOCObj;
|
||||
}
|
||||
if (string.IsNullOrEmpty(key))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (context.Env.CheckObjMonitorState(key, out List<string> exps)) // 如果新的数据处于查看状态,通知UI进行更新?交给运行环境判断?
|
||||
{
|
||||
context.Env.MonitorObjectNotification(nodeModel.Guid, data, sourceType); // 对象处于监视状态,通知UI更新数据显示
|
||||
if (exps.Count > 0)
|
||||
{
|
||||
// 表达式环境下判断是否需要执行中断
|
||||
bool isExpInterrupt = false;
|
||||
string? exp = "";
|
||||
// 判断执行监视表达式,直到为 true 时退出
|
||||
for (int i = 0; i < exps.Count && !isExpInterrupt; i++)
|
||||
{
|
||||
exp = exps[i];
|
||||
if (string.IsNullOrEmpty(exp)) continue;
|
||||
isExpInterrupt = SereinConditionParser.To(data, exp);
|
||||
}
|
||||
|
||||
if (isExpInterrupt) // 触发中断
|
||||
{
|
||||
InterruptClass interruptClass = InterruptClass.Branch; // 分支中断
|
||||
if (context.Env.SetNodeInterrupt(nodeModel.Guid, interruptClass))
|
||||
{
|
||||
context.Env.TriggerInterrupt(nodeModel.Guid, exp, InterruptTriggerEventArgs.InterruptTriggerType.Exp);
|
||||
var cancelType = await nodeModel.DebugSetting.GetInterruptTask();
|
||||
await Console.Out.WriteLineAsync($"[{data}]中断已{cancelType},开始执行后继分支");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 释放对象
|
||||
/// </summary>
|
||||
public void ReleaseFlowData()
|
||||
{
|
||||
if (typeof(IDisposable).IsAssignableFrom(FlowData?.GetType()) && FlowData is IDisposable disposable)
|
||||
{
|
||||
disposable?.Dispose();
|
||||
}
|
||||
this.FlowData = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取节点数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public object? GetFlowData()
|
||||
{
|
||||
return this.FlowData;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Utils.SereinExpression;
|
||||
using System.Reactive;
|
||||
using System.Reflection.Metadata;
|
||||
|
||||
namespace Serein.NodeFlow.Model
|
||||
{
|
||||
@@ -33,17 +34,52 @@ namespace Serein.NodeFlow.Model
|
||||
/// </summary>
|
||||
public override void OnLoading()
|
||||
{
|
||||
Console.WriteLine("SingleExpOpNode 暂未实现 OnLoading");
|
||||
var pd = new ParameterDetails
|
||||
{
|
||||
Index = 0,
|
||||
Name = "Exp",
|
||||
DataType = typeof(object),
|
||||
ExplicitType = typeof(object),
|
||||
IsExplicitData = false,
|
||||
DataValue = string.Empty,
|
||||
ArgDataSourceNodeGuid = string.Empty,
|
||||
ArgDataSourceType = ConnectionArgSourceType.GetPreviousNodeData,
|
||||
NodeModel = this,
|
||||
Convertor = null,
|
||||
ExplicitTypeName = "Value",
|
||||
Items = Array.Empty<string>(),
|
||||
};
|
||||
|
||||
this.MethodDetails.ParameterDetailss = new ParameterDetails[] { pd };
|
||||
}
|
||||
|
||||
|
||||
public override Task<object?> ExecutingAsync(IDynamicContext context)
|
||||
public override async Task<object?> ExecutingAsync(IDynamicContext context)
|
||||
{
|
||||
var data = context.TransmissionData(this); // 表达式节点使用上一节点数据
|
||||
object? parameter = null;// context.TransmissionData(this); // 表达式节点使用上一节点数据
|
||||
var pd = MethodDetails.ParameterDetailss[0];
|
||||
|
||||
if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeData)
|
||||
{
|
||||
// 使用自定义节点的参数
|
||||
parameter = context.GetFlowData(pd.ArgDataSourceNodeGuid);
|
||||
}
|
||||
else if (pd.ArgDataSourceType == ConnectionArgSourceType.GetOtherNodeDataOfInvoke)
|
||||
{
|
||||
// 立刻调用目标节点,然后使用其返回值
|
||||
parameter = await Env.InvokeNodeAsync(context, pd.ArgDataSourceNodeGuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 条件节点透传上一节点的数据
|
||||
parameter = context.TransmissionData(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var newData = SerinExpressionEvaluator.Evaluate(Expression, data, out bool isChange);
|
||||
var newData = SerinExpressionEvaluator.Evaluate(Expression, parameter, out bool isChange);
|
||||
Console.WriteLine(newData);
|
||||
object? result = null;
|
||||
if (isChange)
|
||||
@@ -52,7 +88,7 @@ namespace Serein.NodeFlow.Model
|
||||
}
|
||||
else
|
||||
{
|
||||
result = data;
|
||||
result = parameter;
|
||||
}
|
||||
|
||||
context.NextOrientation = ConnectionInvokeType.IsSucceed;
|
||||
@@ -62,7 +98,7 @@ namespace Serein.NodeFlow.Model
|
||||
{
|
||||
context.NextOrientation = ConnectionInvokeType.IsError;
|
||||
RuningException = ex;
|
||||
return Task.FromResult(data);
|
||||
return parameter;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,785 +0,0 @@
|
||||
using Serein.Library.Api;
|
||||
using Serein.Library.Core.NodeFlow;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Serein.NodeFlow.Tool
|
||||
{
|
||||
/// <summary>
|
||||
/// 对于实例创建的表达式树反射
|
||||
/// </summary>
|
||||
public static class ExpressionHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 缓存表达式树反射方法
|
||||
/// </summary>
|
||||
private static ConcurrentDictionary<string, Delegate> Cache { get; } = new ConcurrentDictionary<string, Delegate>();
|
||||
|
||||
public static List<string> GetCacheKey()
|
||||
{
|
||||
return [.. Cache.Keys];
|
||||
}
|
||||
|
||||
#region 基于类型的表达式反射构建委托
|
||||
|
||||
#region 属性、字段的委托创建(表达式反射)
|
||||
|
||||
/// <summary>
|
||||
/// 动态获取属性值
|
||||
/// </summary>
|
||||
public static Delegate PropertyGetter(Type type, string propertyName)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{propertyName}.Getter";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateGetterDelegate(type, propertyName));
|
||||
}
|
||||
/// <summary>
|
||||
/// 动态获取属性值
|
||||
/// </summary>
|
||||
private static Delegate CreateGetterDelegate(Type type, string propertyName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var property = Expression.Property(Expression.Convert(parameter, type), propertyName);
|
||||
var lambda = Expression.Lambda(Expression.Convert(property, typeof(object)), parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态设置属性值
|
||||
/// </summary>
|
||||
public static Delegate PropertySetter(Type type, string propertyName)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{propertyName}.Setter";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateSetterDelegate(type, propertyName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态设置属性值
|
||||
/// </summary>
|
||||
private static Delegate CreateSetterDelegate(Type type, string propertyName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var value = Expression.Parameter(typeof(object), "value");
|
||||
var property = Expression.Property(Expression.Convert(parameter, type), propertyName);
|
||||
var assign = Expression.Assign(property, Expression.Convert(value, property.Type));
|
||||
var lambda = Expression.Lambda(assign, parameter, value);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态获取字段值
|
||||
/// </summary>
|
||||
public static Delegate FieldGetter(Type type, string fieldName)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{fieldName}.FieldGetter";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateFieldGetterDelegate(type, fieldName));
|
||||
}
|
||||
/// <summary>
|
||||
/// 动态获取字段值
|
||||
/// </summary>
|
||||
private static Delegate CreateFieldGetterDelegate(Type type, string fieldName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var field = Expression.Field(Expression.Convert(parameter, type), fieldName);
|
||||
var lambda = Expression.Lambda(Expression.Convert(field, typeof(object)), parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态设置字段值
|
||||
/// </summary>
|
||||
public static Delegate FieldSetter(Type type, string fieldName)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{fieldName}.FieldSetter";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateFieldSetterDelegate(type, fieldName));
|
||||
}
|
||||
/// <summary>
|
||||
/// 动态设置字段值
|
||||
/// </summary>
|
||||
private static Delegate CreateFieldSetterDelegate(Type type, string fieldName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var value = Expression.Parameter(typeof(object), "value");
|
||||
var field = Expression.Field(Expression.Convert(parameter, type), fieldName);
|
||||
var assign = Expression.Assign(field, Expression.Convert(value, field.Type));
|
||||
var lambda = Expression.Lambda(assign, parameter, value);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建无参数,无返回值方法
|
||||
/// </summary>
|
||||
public static Delegate MethodCaller(Type type, MethodInfo methodInfo)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodInfo.Name}.MethodCaller";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate(type, methodInfo));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建无参数,无返回值方法
|
||||
/// </summary>
|
||||
private static Delegate CreateMethodCallerDelegate(Type type, MethodInfo methodInfo)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type), methodInfo);
|
||||
var lambda = Expression.Lambda(methodCall, parameter);
|
||||
// Action<object>
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建无参数,有返回值方法
|
||||
/// </summary>
|
||||
public static Delegate MethodCallerHaveResult(Type type, MethodInfo methodInfo)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodInfo.Name}.MethodCallerHaveResult";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegateHaveResult(type, methodInfo));
|
||||
}
|
||||
/// <summary>
|
||||
/// 表达式树构建无参数,有返回值方法
|
||||
/// </summary>
|
||||
private static Delegate CreateMethodCallerDelegateHaveResult(Type type, MethodInfo methodInfo)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type), methodInfo);
|
||||
|
||||
if(MethodDetailsHelperTmp.IsGenericTask(methodInfo.ReturnType,out var taskResult))
|
||||
{
|
||||
if(taskResult is null)
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, Task>>(Expression.Convert(methodCall, typeof(Task)), parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
else
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, Task<object>>>(Expression.Convert(methodCall, typeof(Task<object>)), parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, object>>(Expression.Convert(methodCall, typeof(object)), parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建多个参数,无返回值的方法
|
||||
/// </summary>
|
||||
public static Delegate MethodCaller(Type type, MethodInfo methodInfo, params Type[] parameterTypes)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodInfo.Name}.MethodCaller";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate(type, methodInfo, parameterTypes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建多个参数,无返回值的方法
|
||||
/// </summary>
|
||||
private static Delegate CreateMethodCallerDelegate(Type type, MethodInfo methodInfo, Type[] parameterTypes)
|
||||
{
|
||||
/* var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
|
||||
var arguments = parameterTypes.Select((t, i) => Expression.Parameter(typeof(object), $"arg{i}")).ToArray();
|
||||
|
||||
var convertedArguments = arguments.Select((arg, i) => Expression.Convert(arg, parameterTypes[i])).ToArray();
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type),
|
||||
methodInfo,
|
||||
convertedArguments);
|
||||
var lambda = Expression.Lambda(methodCall, new[] { parameter }.Concat(arguments));
|
||||
var tmpAction = lambda.Compile();
|
||||
|
||||
// Action<object, object[]>
|
||||
return lambda.Compile();*/
|
||||
|
||||
var instanceParam = Expression.Parameter(typeof(object), "instance");
|
||||
var argsParam = Expression.Parameter(typeof(object[]), "args");
|
||||
|
||||
// 创建参数表达式
|
||||
var convertedArgs = parameterTypes.Select((paramType, index) =>
|
||||
Expression.Convert(Expression.ArrayIndex(argsParam, Expression.Constant(index)), paramType)
|
||||
).ToArray();
|
||||
|
||||
|
||||
// 创建方法调用表达式
|
||||
var methodCall = Expression.Call(
|
||||
Expression.Convert(instanceParam, type),
|
||||
methodInfo,
|
||||
convertedArgs
|
||||
);
|
||||
|
||||
// 创建 lambda 表达式
|
||||
var lambda = Expression.Lambda(
|
||||
methodCall,
|
||||
instanceParam,
|
||||
argsParam
|
||||
);
|
||||
|
||||
// Func<object, object[], object>
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建多个参数,有返回值的方法
|
||||
/// </summary>
|
||||
public static Delegate MethodCallerHaveResult(Type type, MethodInfo methodInfo, Type[] parameterTypes)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodInfo.Name}.MethodCallerHaveResult";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegateHaveResult(type, methodInfo, parameterTypes));
|
||||
}
|
||||
/// <summary>
|
||||
/// 表达式树构建多个参数,有返回值的方法
|
||||
/// </summary>
|
||||
private static Delegate CreateMethodCallerDelegateHaveResult(Type type, MethodInfo methodInfo, Type[] parameterTypes)
|
||||
{
|
||||
/*var instanceParam = Expression.Parameter(typeof(object), "instance");
|
||||
var argsParam = Expression.Parameter(typeof(object[]), "args");
|
||||
|
||||
// 创建参数表达式
|
||||
var convertedArgs = parameterTypes.Select((paramType, index) =>
|
||||
Expression.Convert(Expression.ArrayIndex(argsParam, Expression.Constant(index)), paramType)
|
||||
).ToArray();
|
||||
|
||||
|
||||
// 创建方法调用表达式
|
||||
var methodCall = Expression.Call(
|
||||
Expression.Convert(instanceParam, type),
|
||||
methodInfo,
|
||||
convertedArgs
|
||||
);
|
||||
|
||||
// 创建 lambda 表达式
|
||||
var lambda = Expression.Lambda(
|
||||
Expression.Convert(methodCall, typeof(object)),
|
||||
instanceParam,
|
||||
argsParam
|
||||
);
|
||||
|
||||
// Func<object, object[], object>
|
||||
return lambda.Compile();*/
|
||||
|
||||
var instanceParam = Expression.Parameter(typeof(object), "instance");
|
||||
var argsParam = Expression.Parameter(typeof(object[]), "args");
|
||||
|
||||
// 创建参数表达式
|
||||
var convertedArgs = parameterTypes.Select((paramType, index) =>
|
||||
Expression.Convert(Expression.ArrayIndex(argsParam, Expression.Constant(index)), paramType)
|
||||
).ToArray();
|
||||
|
||||
|
||||
// 创建方法调用表达式
|
||||
var methodCall = Expression.Call(
|
||||
Expression.Convert(instanceParam, type),
|
||||
methodInfo,
|
||||
convertedArgs
|
||||
);
|
||||
|
||||
if (MethodDetailsHelperTmp.IsGenericTask(methodInfo.ReturnType, out var taskResult))
|
||||
{
|
||||
if (taskResult is null)
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, object[], Task>>
|
||||
(Expression.Convert(methodCall, typeof(Task)), instanceParam, argsParam);
|
||||
return lambda.Compile();
|
||||
}
|
||||
else
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, object[], Task<object>>>
|
||||
(Expression.Convert(methodCall, typeof(Task<object>)), instanceParam, argsParam);
|
||||
return lambda.Compile();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var lambda = Expression.Lambda<Func<object, object[], object>>
|
||||
(Expression.Convert(methodCall, typeof(object)), instanceParam, argsParam);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建无参数,有返回值(Task<object>)的方法(触发器)
|
||||
/// </summary>
|
||||
public static Delegate MethodCallerAsync(Type type, MethodInfo methodInfo)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodInfo.Name}.MethodCallerAsync";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegateAsync(type, methodInfo));
|
||||
}
|
||||
/// <summary>
|
||||
/// 表达式树构建无参数,有返回值(Task<object>)的方法(触发器)
|
||||
/// </summary>
|
||||
private static Delegate CreateMethodCallerDelegateAsync(Type type, MethodInfo methodInfo)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type), methodInfo);
|
||||
var lambda = Expression.Lambda<Func<object, Task<object>>>(
|
||||
Expression.Convert(methodCall, typeof(Task<object>)), parameter);
|
||||
// Func<object, Task<object>>
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建多个参数,有返回值(Task-object)的方法(触发器)
|
||||
/// </summary>
|
||||
public static Delegate MethodCallerAsync(Type type, MethodInfo method, params Type[] parameterTypes)
|
||||
{
|
||||
|
||||
string cacheKey = $"{type.FullName}.{method.Name}.MethodCallerAsync";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegateAsync(type, method, parameterTypes));
|
||||
}
|
||||
/// <summary>
|
||||
/// 表达式树构建多个参数,有返回值(Task<object>)的方法(触发器)
|
||||
/// </summary>
|
||||
private static Delegate CreateMethodCallerDelegateAsync(Type type, MethodInfo methodInfo, Type[] parameterTypes)
|
||||
{
|
||||
var instanceParam = Expression.Parameter(typeof(object), "instance");
|
||||
var argsParam = Expression.Parameter(typeof(object[]), "args");
|
||||
|
||||
// 创建参数表达式
|
||||
var convertedArgs = parameterTypes.Select((paramType, index) =>
|
||||
Expression.Convert(Expression.ArrayIndex(argsParam, Expression.Constant(index)), paramType)
|
||||
).ToArray();
|
||||
|
||||
|
||||
// 创建方法调用表达式
|
||||
var methodCall = Expression.Call(
|
||||
Expression.Convert(instanceParam, type),
|
||||
methodInfo,
|
||||
convertedArgs
|
||||
);
|
||||
|
||||
// 创建 lambda 表达式
|
||||
var lambda = Expression.Lambda<Func<object, object[], Task<IFlipflopContext>>>(
|
||||
Expression.Convert(methodCall, typeof(Task<IFlipflopContext>)),
|
||||
instanceParam,
|
||||
argsParam
|
||||
);
|
||||
//获取返回类型
|
||||
//var returnType = methodInfo.ReturnType;
|
||||
//var lambda = Expression.Lambda(
|
||||
// typeof(Func<,,>).MakeGenericType(typeof(object), typeof(object[]), returnType),
|
||||
// Expression.Convert(methodCall, returnType),
|
||||
// instanceParam,
|
||||
// argsParam
|
||||
// );
|
||||
|
||||
|
||||
//var resule = task.DynamicInvoke((object)[Activator.CreateInstance(type), [new DynamicContext(null)]]);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 单参数
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建单参数,无返回值的方法
|
||||
/// </summary>
|
||||
public static Delegate MethodCaller(Type type, string methodName, Type parameterType)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodName}.MethodCallerWithParam";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate(type, methodName, parameterType));
|
||||
}
|
||||
/// <summary>
|
||||
/// 表达式树构建单参数,无返回值的方法
|
||||
/// </summary>
|
||||
private static Delegate CreateMethodCallerDelegate(Type type, string methodName, Type parameterType)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var argument = Expression.Parameter(typeof(object), "argument");
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type),
|
||||
type.GetMethod(methodName, [parameterType])!,
|
||||
Expression.Convert(argument, parameterType));
|
||||
var lambda = Expression.Lambda(methodCall, parameter, argument);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表达式树构建单参数,有返回值的方法
|
||||
/// </summary>
|
||||
public static Delegate MethodCallerWithResult(Type type, string methodName, Type parameterType, Type returnType)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodName}.MethodCallerWithResult";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegateWithResult(type, methodName, parameterType, returnType));
|
||||
}
|
||||
/// <summary>
|
||||
/// 表达式树构建单参数,有返回值的方法
|
||||
/// </summary>
|
||||
private static Delegate CreateMethodCallerDelegateWithResult(Type type, string methodName, Type parameterType, Type returnType)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var argument = Expression.Parameter(typeof(object), "argument");
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type),
|
||||
type.GetMethod(methodName, [parameterType])!,
|
||||
Expression.Convert(argument, parameterType));
|
||||
var lambda = Expression.Lambda(Expression.Convert(methodCall, typeof(object)), parameter, argument);
|
||||
|
||||
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 泛型表达式反射构建方法(已注释)
|
||||
/*
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动态获取属性值
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TProperty"></typeparam>
|
||||
/// <param name="propertyName"></param>
|
||||
/// <returns></returns>
|
||||
public static Func<T, TProperty> PropertyGetter<T, TProperty>(string propertyName)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{propertyName}.Getter";
|
||||
return (Func<T, TProperty>)Cache.GetOrAdd(cacheKey, _ => CreateGetterDelegate<T, TProperty>(propertyName));
|
||||
}
|
||||
|
||||
private static Func<T, TProperty> CreateGetterDelegate<T, TProperty>(string propertyName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var property = Expression.Property(parameter, propertyName);
|
||||
var lambda = Expression.Lambda<Func<T, TProperty>>(property, parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态设置属性值
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TProperty"></typeparam>
|
||||
/// <param name="propertyName"></param>
|
||||
/// <returns></returns>
|
||||
public static Action<T, TProperty> PropertySetter<T, TProperty>(string propertyName)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{propertyName}.Setter";
|
||||
return (Action<T, TProperty>)Cache.GetOrAdd(cacheKey, _ => CreateSetterDelegate<T, TProperty>(propertyName));
|
||||
}
|
||||
|
||||
private static Action<T, TProperty> CreateSetterDelegate<T, TProperty>(string propertyName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var value = Expression.Parameter(typeof(TProperty), "value");
|
||||
var property = Expression.Property(parameter, propertyName);
|
||||
var assign = Expression.Assign(property, value);
|
||||
var lambda = Expression.Lambda<Action<T, TProperty>>(assign, parameter, value);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态获取字段值
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TField"></typeparam>
|
||||
/// <param name="fieldName"></param>
|
||||
/// <returns></returns>
|
||||
public static Func<T, TField> FieldGetter<T, TField>(string fieldName)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{fieldName}.FieldGetter";
|
||||
return (Func<T, TField>)Cache.GetOrAdd(cacheKey, _ => CreateFieldGetterDelegate<T, TField>(fieldName));
|
||||
}
|
||||
|
||||
private static Func<T, TField> CreateFieldGetterDelegate<T, TField>(string fieldName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var field = Expression.Field(parameter, fieldName);
|
||||
var lambda = Expression.Lambda<Func<T, TField>>(field, parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态设置字段值
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TField"></typeparam>
|
||||
/// <param name="fieldName"></param>
|
||||
/// <returns></returns>
|
||||
public static Action<T, TField> FieldSetter<T, TField>(string fieldName)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{fieldName}.FieldSetter";
|
||||
return (Action<T, TField>)Cache.GetOrAdd(cacheKey, _ => CreateFieldSetterDelegate<T, TField>(fieldName));
|
||||
}
|
||||
|
||||
private static Action<T, TField> CreateFieldSetterDelegate<T, TField>(string fieldName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var value = Expression.Parameter(typeof(TField), "value");
|
||||
var field = Expression.Field(parameter, fieldName);
|
||||
var assign = Expression.Assign(field, value);
|
||||
var lambda = Expression.Lambda<Action<T, TField>>(assign, parameter, value);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动态调用无参数方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="methodName"></param>
|
||||
/// <returns></returns>
|
||||
public static Action<T> MethodCaller<T>(string methodName)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{methodName}.MethodCaller";
|
||||
return (Action<T>)Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate<T>(methodName));
|
||||
}
|
||||
|
||||
private static Action<T> CreateMethodCallerDelegate<T>(string methodName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var methodCall = Expression.Call(parameter, typeof(T).GetMethod(methodName));
|
||||
var lambda = Expression.Lambda<Action<T>>(methodCall, parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态调用无参有返回值方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <param name="methodName"></param>
|
||||
/// <returns></returns>
|
||||
public static Func<T, TResult> MethodCallerHaveResul<T, TResult>(string methodName)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{methodName}.MethodCaller";
|
||||
return (Func<T, TResult>)Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegateHaveResult<T, TResult>(methodName));
|
||||
}
|
||||
|
||||
private static Func<T, TResult> CreateMethodCallerDelegateHaveResult<T, TResult>(string methodName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var methodCall = Expression.Call(parameter, typeof(T).GetMethod(methodName));
|
||||
var lambda = Expression.Lambda<Func<T, TResult>>(methodCall, parameter);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动态调用单参数无返回值的方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TParam"></typeparam>
|
||||
/// <param name="methodName"></param>
|
||||
/// <returns></returns>
|
||||
public static Action<T, TParam> MethodCaller<T, TParam>(string methodName)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{methodName}.MethodCallerWithParam";
|
||||
return (Action<T, TParam>)Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate<T, TParam>(methodName));
|
||||
}
|
||||
|
||||
private static Action<T, TParam> CreateMethodCallerDelegate<T, TParam>(string methodName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var argument = Expression.Parameter(typeof(TParam), "argument");
|
||||
var methodCall = Expression.Call(parameter, typeof(T).GetMethod(methodName), argument);
|
||||
var lambda = Expression.Lambda<Action<T, TParam>>(methodCall, parameter, argument);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态调用单参数有返回值的方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TParam"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <param name="methodName"></param>
|
||||
/// <returns></returns>
|
||||
public static Func<T, TParam, TResult> MethodCallerWithResult<T, TParam, TResult>(string methodName)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{methodName}.MethodCallerWithResult";
|
||||
return (Func<T, TParam, TResult>)Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate<T, TParam, TResult>(methodName));
|
||||
}
|
||||
|
||||
private static Func<T, TParam, TResult> CreateMethodCallerDelegate<T, TParam, TResult>(string methodName)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var argument = Expression.Parameter(typeof(TParam), "argument");
|
||||
var methodCall = Expression.Call(parameter, typeof(T).GetMethod(methodName), argument);
|
||||
var lambda = Expression.Lambda<Func<T, TParam, TResult>>(methodCall, parameter, argument);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 动态调用多参无返回值的方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="methodName"></param>
|
||||
/// <param name="parameterTypes"></param>
|
||||
/// <returns></returns>
|
||||
public static Action<T, object[]> MethodCaller<T>(string methodName, params Type[] parameterTypes)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{methodName}.MethodCaller";
|
||||
return (Action<T, object[]>)Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate<T>(methodName, parameterTypes));
|
||||
}
|
||||
|
||||
private static Action<T, object[]> CreateMethodCallerDelegate<T>(string methodName, Type[] parameterTypes)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(T), "instance");
|
||||
var arguments = parameterTypes.Select((type, index) =>
|
||||
Expression.Parameter(typeof(object), $"arg{index}")
|
||||
).ToList();
|
||||
|
||||
var convertedArguments = arguments.Select((arg, index) =>
|
||||
Expression.Convert(arg, parameterTypes[index])
|
||||
).ToList();
|
||||
|
||||
var methodInfo = typeof(T).GetMethod(methodName, parameterTypes);
|
||||
|
||||
if (methodInfo == null)
|
||||
{
|
||||
throw new ArgumentException($"Method '{methodName}' not found in type '{typeof(T).FullName}' with given parameter types.");
|
||||
}
|
||||
|
||||
var methodCall = Expression.Call(parameter, methodInfo, convertedArguments);
|
||||
var lambda = Expression.Lambda<Action<T, object[]>>(methodCall, new[] { parameter }.Concat(arguments));
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 动态调用多参有返回值的方法
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="TResult"></typeparam>
|
||||
/// <param name="methodName"></param>
|
||||
/// <param name="parameterTypes"></param>
|
||||
/// <returns></returns>
|
||||
public static Func<T, object[], TResult> MethodCallerHaveResult<T, TResult>(string methodName, Type[] parameterTypes)
|
||||
{
|
||||
string cacheKey = $"{typeof(T).FullName}.{methodName}.MethodCallerHaveResult";
|
||||
return (Func<T, object[], TResult>)Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate<T, TResult>(methodName, parameterTypes));
|
||||
}
|
||||
|
||||
private static Func<T, object[], TResult> CreateMethodCallerDelegate<T, TResult>(string methodName, Type[] parameterTypes)
|
||||
{
|
||||
var instanceParam = Expression.Parameter(typeof(T), "instance");
|
||||
var argsParam = Expression.Parameter(typeof(object[]), "args");
|
||||
|
||||
var convertedArgs = new Expression[parameterTypes.Length];
|
||||
for (int i = 0; i < parameterTypes.Length; i++)
|
||||
{
|
||||
var index = Expression.Constant(i);
|
||||
var argType = parameterTypes[i];
|
||||
var arrayIndex = Expression.ArrayIndex(argsParam, index);
|
||||
var convertedArg = Expression.Convert(arrayIndex, argType);
|
||||
convertedArgs[i] = convertedArg;
|
||||
}
|
||||
|
||||
var methodInfo = typeof(T).GetMethod(methodName, parameterTypes);
|
||||
|
||||
if (methodInfo == null)
|
||||
{
|
||||
throw new ArgumentException($"Method '{methodName}' not found in type '{typeof(T).FullName}' with given parameter types.");
|
||||
}
|
||||
|
||||
var methodCall = Expression.Call(instanceParam, methodInfo, convertedArgs);
|
||||
var lambda = Expression.Lambda<Func<T, object[], TResult>>(methodCall, instanceParam, argsParam);
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region 暂时不删(已注释)
|
||||
/* /// <summary>
|
||||
/// 表达式树构建多个参数,有返回值的方法
|
||||
/// </summary>
|
||||
public static Delegate MethodCallerHaveResult(Type type, string methodName, Type[] parameterTypes)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodName}.MethodCallerHaveResult";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegateHaveResult(type, methodName, parameterTypes));
|
||||
}
|
||||
|
||||
private static Delegate CreateMethodCallerDelegateHaveResult(Type type, string methodName, Type[] parameterTypes)
|
||||
{
|
||||
var instanceParam = Expression.Parameter(typeof(object), "instance");
|
||||
var argsParam = Expression.Parameter(typeof(object[]), "args");
|
||||
var convertedArgs = parameterTypes.Select((paramType, index) =>
|
||||
Expression.Convert(Expression.ArrayIndex(argsParam, Expression.Constant(index)), paramType)
|
||||
).ToArray();
|
||||
var methodCall = Expression.Call(Expression.Convert(instanceParam, type), type.GetMethod(methodName, parameterTypes), convertedArgs);
|
||||
var lambda = Expression.Lambda(Expression.Convert(methodCall, typeof(object)), instanceParam, argsParam);
|
||||
return lambda.Compile();
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
/*/// <summary>
|
||||
/// 表达式反射 构建 无返回值、无参数 的委托
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="methodName"></param>
|
||||
/// <param name="parameterTypes"></param>
|
||||
/// <returns></returns>
|
||||
public static Delegate MethodCaller(Type type, string methodName, Type[] parameterTypes)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodName}.{string.Join(",", parameterTypes.Select(t => t.FullName))}.MethodCaller";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegate(type, methodName, parameterTypes));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表达式反射 构建 无返回值、无参数 的委托
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="methodName"></param>
|
||||
/// <param name="parameterTypes"></param>
|
||||
/// <returns></returns>
|
||||
private static Delegate CreateMethodCallerDelegate(Type type, string methodName, Type[] parameterTypes)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var arguments = parameterTypes.Select((paramType, index) => Expression.Parameter(paramType, $"param{index}")).ToArray();
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type), type.GetMethod(methodName, parameterTypes), arguments);
|
||||
|
||||
var delegateType = Expression.GetActionType(new[] { typeof(object) }.Concat(parameterTypes).ToArray());
|
||||
var lambda = Expression.Lambda(delegateType, methodCall, new[] { parameter }.Concat(arguments).ToArray());
|
||||
return lambda.Compile();
|
||||
}
|
||||
*/
|
||||
/*public static Delegate MethodCallerHaveResult(Type type, string methodName, Type returnType, Type[] parameterTypes)
|
||||
{
|
||||
string cacheKey = $"{type.FullName}.{methodName}.{string.Join(",", parameterTypes.Select(t => t.FullName))}.MethodCallerHaveResult";
|
||||
return Cache.GetOrAdd(cacheKey, _ => CreateMethodCallerDelegateHaveResult(type, methodName, returnType, parameterTypes));
|
||||
}
|
||||
|
||||
private static Delegate CreateMethodCallerDelegateHaveResult(Type type, string methodName, Type returnType, Type[] parameterTypes)
|
||||
{
|
||||
var parameter = Expression.Parameter(typeof(object), "instance");
|
||||
var arguments = parameterTypes.Select((paramType, index) => Expression.Parameter(paramType, $"param{index}")).ToArray();
|
||||
var methodCall = Expression.Call(Expression.Convert(parameter, type), type.GetMethod(methodName, parameterTypes), arguments);
|
||||
|
||||
var delegateType = Expression.GetFuncType(new[] { typeof(object) }.Concat(parameterTypes).Concat(new[] { typeof(object) }).ToArray());
|
||||
var lambda = Expression.Lambda(delegateType, Expression.Convert(methodCall, typeof(object)), new[] { parameter }.Concat(arguments).ToArray());
|
||||
return lambda.Compile();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression.Resolver
|
||||
{
|
||||
public class BoolConditionResolver : SereinConditionResolver
|
||||
{
|
||||
public enum Operator
|
||||
{
|
||||
/// <summary>
|
||||
/// 是
|
||||
/// </summary>
|
||||
Is
|
||||
}
|
||||
|
||||
public Operator Op { get; set; }
|
||||
public bool Value { get; set; }
|
||||
|
||||
public override bool Evaluate(object obj)
|
||||
{
|
||||
|
||||
if (obj is bool boolObj)
|
||||
{
|
||||
return boolObj == Value;
|
||||
/*switch (Op)
|
||||
{
|
||||
case Operator.Is:
|
||||
return boolObj == Value;
|
||||
}*/
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression.Resolver
|
||||
{
|
||||
public class MemberConditionResolver<T> : SereinConditionResolver where T : struct, IComparable<T>
|
||||
{
|
||||
//public string MemberPath { get; set; }
|
||||
public ValueTypeConditionResolver<T>.Operator Op { get; set; }
|
||||
public object? TargetObj { get; set; }
|
||||
public T Value { get; set; }
|
||||
|
||||
public string ArithmeticExpression { get; set; }
|
||||
public T RangeEnd { get; internal set; }
|
||||
public T RangeStart { get; internal set; }
|
||||
|
||||
public override bool Evaluate(object? obj)
|
||||
{
|
||||
//object? memberValue = GetMemberValue(obj, MemberPath);
|
||||
|
||||
|
||||
if (TargetObj is T typedObj)
|
||||
{
|
||||
return new ValueTypeConditionResolver<T>
|
||||
{
|
||||
RangeStart = RangeStart,
|
||||
RangeEnd = RangeEnd,
|
||||
Op = Op,
|
||||
Value = Value,
|
||||
ArithmeticExpression = ArithmeticExpression,
|
||||
}.Evaluate(typedObj);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//private object? GetMemberValue(object? obj, string memberPath)
|
||||
//{
|
||||
// string[] members = memberPath[1..].Split('.');
|
||||
// foreach (var member in members)
|
||||
// {
|
||||
// if (obj == null) return null;
|
||||
// Type type = obj.GetType();
|
||||
// PropertyInfo? propertyInfo = type.GetProperty(member);
|
||||
// FieldInfo? fieldInfo = type.GetField(member);
|
||||
// if (propertyInfo != null)
|
||||
// obj = propertyInfo.GetValue(obj);
|
||||
// else if (fieldInfo != null)
|
||||
// obj = fieldInfo.GetValue(obj);
|
||||
// else
|
||||
// throw new ArgumentException($"Member {member} not found in type {type.FullName}");
|
||||
// }
|
||||
// return obj;
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression.Resolver
|
||||
{
|
||||
public class MemberStringConditionResolver : SereinConditionResolver
|
||||
{
|
||||
public string MemberPath { get; set; }
|
||||
|
||||
public StringConditionResolver.Operator Op { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
|
||||
public override bool Evaluate(object obj)
|
||||
{
|
||||
object memberValue;
|
||||
if (!string.IsNullOrWhiteSpace(MemberPath))
|
||||
{
|
||||
memberValue = GetMemberValue(obj, MemberPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
memberValue = obj;
|
||||
}
|
||||
|
||||
if (memberValue is string strObj)
|
||||
{
|
||||
return new StringConditionResolver
|
||||
{
|
||||
Op = Op,
|
||||
Value = Value
|
||||
}.Evaluate(strObj);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private object? GetMemberValue(object? obj, string memberPath)
|
||||
{
|
||||
string[] members = memberPath[1..].Split('.');
|
||||
foreach (var member in members)
|
||||
{
|
||||
|
||||
if (obj is null) return null;
|
||||
|
||||
Type type = obj.GetType();
|
||||
PropertyInfo? propertyInfo = type.GetProperty(member);
|
||||
FieldInfo? fieldInfo = type.GetField(member);
|
||||
if (propertyInfo != null)
|
||||
obj = propertyInfo.GetValue(obj);
|
||||
else if (fieldInfo != null)
|
||||
obj = fieldInfo.GetValue(obj);
|
||||
else
|
||||
throw new ArgumentException($"Member {member} not found in type {type.FullName}");
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static string GetArithmeticExpression(string part)
|
||||
{
|
||||
int startIndex = part.IndexOf('[');
|
||||
int endIndex = part.IndexOf(']');
|
||||
if (startIndex >= 0 && endIndex > startIndex)
|
||||
{
|
||||
return part.Substring(startIndex + 1, endIndex - startIndex - 1);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression.Resolver
|
||||
{
|
||||
public class PassConditionResolver : SereinConditionResolver
|
||||
{
|
||||
public Operator Op { get; set; }
|
||||
public override bool Evaluate(object obj)
|
||||
{
|
||||
/*return Op switch
|
||||
{
|
||||
Operator.Pass => true,
|
||||
Operator.NotPass => false,
|
||||
_ => throw new NotSupportedException("不支持的条件类型")
|
||||
};*/
|
||||
switch (Op)
|
||||
{
|
||||
case Operator.Pass:
|
||||
return true;
|
||||
case Operator.NotPass:
|
||||
return false;
|
||||
default:
|
||||
throw new NotSupportedException("不支持的条件类型");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public enum Operator
|
||||
{
|
||||
Pass,
|
||||
NotPass,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression.Resolver
|
||||
{
|
||||
public class StringConditionResolver : SereinConditionResolver
|
||||
{
|
||||
public enum Operator
|
||||
{
|
||||
/// <summary>
|
||||
/// 出现过
|
||||
/// </summary>
|
||||
Contains,
|
||||
/// <summary>
|
||||
/// 没有出现过
|
||||
/// </summary>
|
||||
DoesNotContain,
|
||||
/// <summary>
|
||||
/// 相等
|
||||
/// </summary>
|
||||
Equal,
|
||||
/// <summary>
|
||||
/// 不相等
|
||||
/// </summary>
|
||||
NotEqual,
|
||||
/// <summary>
|
||||
/// 起始字符串等于
|
||||
/// </summary>
|
||||
StartsWith,
|
||||
/// <summary>
|
||||
/// 结束字符串等于
|
||||
/// </summary>
|
||||
EndsWith
|
||||
}
|
||||
|
||||
public Operator Op { get; set; }
|
||||
|
||||
public string Value { get; set; }
|
||||
|
||||
|
||||
public override bool Evaluate(object obj)
|
||||
{
|
||||
if (obj is string strObj)
|
||||
{
|
||||
/*return Op switch
|
||||
{
|
||||
Operator.Contains => strObj.Contains(Value),
|
||||
Operator.DoesNotContain => !strObj.Contains(Value),
|
||||
Operator.Equal => strObj == Value,
|
||||
Operator.NotEqual => strObj != Value,
|
||||
Operator.StartsWith => strObj.StartsWith(Value),
|
||||
Operator.EndsWith => strObj.EndsWith(Value),
|
||||
_ => throw new NotSupportedException("不支持的条件类型"),
|
||||
};*/
|
||||
|
||||
switch (Op)
|
||||
{
|
||||
case Operator.Contains:
|
||||
return strObj.Contains(Value);
|
||||
case Operator.DoesNotContain:
|
||||
return !strObj.Contains(Value);
|
||||
case Operator.Equal:
|
||||
return strObj == Value;
|
||||
case Operator.NotEqual:
|
||||
return strObj != Value;
|
||||
case Operator.StartsWith:
|
||||
return strObj.StartsWith(Value);
|
||||
case Operator.EndsWith:
|
||||
return strObj.EndsWith(Value);
|
||||
default:
|
||||
throw new NotSupportedException("不支持的条件类型");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
using Serein.Library.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression.Resolver
|
||||
{
|
||||
public class ValueTypeConditionResolver<T> : SereinConditionResolver where T : struct, IComparable<T>
|
||||
{
|
||||
public enum Operator
|
||||
{
|
||||
/// <summary>
|
||||
/// 不进行任何操作
|
||||
/// </summary>
|
||||
Node,
|
||||
/// <summary>
|
||||
/// 大于
|
||||
/// </summary>
|
||||
GreaterThan,
|
||||
/// <summary>
|
||||
/// 小于
|
||||
/// </summary>
|
||||
LessThan,
|
||||
/// <summary>
|
||||
/// 等于
|
||||
/// </summary>
|
||||
Equal,
|
||||
/// <summary>
|
||||
/// 大于或等于
|
||||
/// </summary>
|
||||
GreaterThanOrEqual,
|
||||
/// <summary>
|
||||
/// 小于或等于
|
||||
/// </summary>
|
||||
LessThanOrEqual,
|
||||
/// <summary>
|
||||
/// 在两者之间
|
||||
/// </summary>
|
||||
InRange,
|
||||
/// <summary>
|
||||
/// 不在两者之间
|
||||
/// </summary>
|
||||
OutOfRange
|
||||
}
|
||||
|
||||
public Operator Op { get; set; }
|
||||
public T Value { get; set; }
|
||||
public T RangeStart { get; set; }
|
||||
public T RangeEnd { get; set; }
|
||||
|
||||
public string ArithmeticExpression { get; set; }
|
||||
|
||||
|
||||
public override bool Evaluate(object obj)
|
||||
{
|
||||
|
||||
var evaluatedValue = obj.ToConvert<T>();
|
||||
if (!string.IsNullOrEmpty(ArithmeticExpression))
|
||||
{
|
||||
evaluatedValue = SerinArithmeticExpressionEvaluator<T>.Evaluate(ArithmeticExpression, evaluatedValue);
|
||||
}
|
||||
|
||||
switch (Op)
|
||||
{
|
||||
case Operator.GreaterThan:
|
||||
return evaluatedValue.CompareTo(Value) > 0;
|
||||
case Operator.LessThan:
|
||||
return evaluatedValue.CompareTo(Value) < 0;
|
||||
case Operator.Equal:
|
||||
return evaluatedValue.CompareTo(Value) == 0;
|
||||
case Operator.GreaterThanOrEqual:
|
||||
return evaluatedValue.CompareTo(Value) >= 0;
|
||||
case Operator.LessThanOrEqual:
|
||||
return evaluatedValue.CompareTo(Value) <= 0;
|
||||
case Operator.InRange:
|
||||
return evaluatedValue.CompareTo(RangeStart) >= 0 && evaluatedValue.CompareTo(RangeEnd) <= 0;
|
||||
case Operator.OutOfRange:
|
||||
return evaluatedValue.CompareTo(RangeStart) < 0 || evaluatedValue.CompareTo(RangeEnd) > 0;
|
||||
}
|
||||
return false;
|
||||
|
||||
//if (obj is T typedObj)
|
||||
//{
|
||||
// numericValue = Convert.ToDouble(typedObj);
|
||||
// numericValue = Convert.ToDouble(obj);
|
||||
// if (!string.IsNullOrEmpty(ArithmeticExpression))
|
||||
// {
|
||||
// numericValue = SerinArithmeticExpressionEvaluator.Evaluate(ArithmeticExpression, numericValue);
|
||||
// }
|
||||
|
||||
// T evaluatedValue = (T)Convert.ChangeType(numericValue, typeof(T));
|
||||
|
||||
// /*return Op switch
|
||||
// {
|
||||
// Operator.GreaterThan => evaluatedValue.CompareTo(Value) > 0,
|
||||
// Operator.LessThan => evaluatedValue.CompareTo(Value) < 0,
|
||||
// Operator.Equal => evaluatedValue.CompareTo(Value) == 0,
|
||||
// Operator.GreaterThanOrEqual => evaluatedValue.CompareTo(Value) >= 0,
|
||||
// Operator.LessThanOrEqual => evaluatedValue.CompareTo(Value) <= 0,
|
||||
// Operator.InRange => evaluatedValue.CompareTo(RangeStart) >= 0 && evaluatedValue.CompareTo(RangeEnd) <= 0,
|
||||
// Operator.OutOfRange => evaluatedValue.CompareTo(RangeStart) < 0 || evaluatedValue.CompareTo(RangeEnd) > 0,
|
||||
// _ => throw new NotSupportedException("不支持的条件类型")
|
||||
// };*/
|
||||
// switch (Op)
|
||||
// {
|
||||
// case Operator.GreaterThan:
|
||||
// return evaluatedValue.CompareTo(Value) > 0;
|
||||
// case Operator.LessThan:
|
||||
// return evaluatedValue.CompareTo(Value) < 0;
|
||||
// case Operator.Equal:
|
||||
// return evaluatedValue.CompareTo(Value) == 0;
|
||||
// case Operator.GreaterThanOrEqual:
|
||||
// return evaluatedValue.CompareTo(Value) >= 0;
|
||||
// case Operator.LessThanOrEqual:
|
||||
// return evaluatedValue.CompareTo(Value) <= 0;
|
||||
// case Operator.InRange:
|
||||
// return evaluatedValue.CompareTo(RangeStart) >= 0 && evaluatedValue.CompareTo(RangeEnd) <= 0;
|
||||
// case Operator.OutOfRange:
|
||||
// return evaluatedValue.CompareTo(RangeStart) < 0 || evaluatedValue.CompareTo(RangeEnd) > 0;
|
||||
// }
|
||||
//}
|
||||
//return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,580 +0,0 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serein.Library.Utils;
|
||||
using Serein.NodeFlow.Tool.SereinExpression.Resolver;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression
|
||||
{
|
||||
|
||||
public class SereinConditionParser
|
||||
{
|
||||
public static bool To<T>(T data, string expression)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(expression))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var parse = ConditionParse(data, expression);
|
||||
var result = parse.Evaluate(data);
|
||||
return result;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static SereinConditionResolver ConditionParse(object? data, string expression)
|
||||
{
|
||||
if (expression.StartsWith('.')) // 表达式前缀属于从上一个节点数据对象获取成员值
|
||||
{
|
||||
return ParseObjectExpression(data, expression);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ParseSimpleExpression(data, expression);
|
||||
}
|
||||
|
||||
|
||||
//bool ContainsArithmeticOperators(string expression)
|
||||
//{
|
||||
// return expression.Contains('+') || expression.Contains('-') || expression.Contains('*') || expression.Contains('/');
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取计算表达式的部分
|
||||
/// </summary>
|
||||
/// <param name="part"></param>
|
||||
/// <returns></returns>
|
||||
private static string GetArithmeticExpression(string part)
|
||||
{
|
||||
int startIndex = part.IndexOf('[');
|
||||
int endIndex = part.IndexOf(']');
|
||||
if (startIndex >= 0 && endIndex > startIndex)
|
||||
{
|
||||
return part.Substring(startIndex + 1, endIndex - startIndex - 1);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取对象指定名称的成员
|
||||
/// </summary>
|
||||
private static object? GetMemberValue(object? obj, string memberPath)
|
||||
{
|
||||
string[] members = memberPath[1..].Split('.');
|
||||
foreach (var member in members)
|
||||
{
|
||||
if (obj is null) return null;
|
||||
Type type = obj.GetType();
|
||||
PropertyInfo? propertyInfo = type.GetProperty(member);
|
||||
FieldInfo? fieldInfo = type.GetField(member);
|
||||
if (propertyInfo != null)
|
||||
obj = propertyInfo.GetValue(obj);
|
||||
else if (fieldInfo != null)
|
||||
obj = fieldInfo.GetValue(obj);
|
||||
else
|
||||
throw new ArgumentException($"Member {member} not found in type {type.FullName}");
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 解析对象表达式
|
||||
/// </summary>
|
||||
private static SereinConditionResolver ParseObjectExpression(object? data, string expression)
|
||||
{
|
||||
var parts = expression.Split(' ');
|
||||
string operatorStr = parts[0]; // 获取操作类型
|
||||
string valueStr; //= string.Join(' ', parts, 1, parts.Length - 1);
|
||||
string memberPath;
|
||||
Type type;
|
||||
object? targetObj;
|
||||
|
||||
// 尝试获取指定类型
|
||||
int typeStartIndex = expression.IndexOf('<');
|
||||
int typeEndIndex = expression.IndexOf('>');
|
||||
if (typeStartIndex + typeStartIndex == -2)
|
||||
{
|
||||
// 如果不需要转为指定类型
|
||||
memberPath = operatorStr;
|
||||
targetObj = SerinExpressionEvaluator.Evaluate("@get " + operatorStr, data, out _);
|
||||
//targetObj = GetMemberValue(data, operatorStr);
|
||||
type = targetObj.GetType();
|
||||
operatorStr = parts[1].ToLower(); //
|
||||
valueStr = string.Join(' ', parts.Skip(2));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 类型语法不正确
|
||||
if (typeStartIndex >= typeEndIndex)
|
||||
{
|
||||
throw new ArgumentException("无效的表达式格式");
|
||||
}
|
||||
memberPath = expression.Substring(0, typeStartIndex).Trim();
|
||||
string typeStr = expression.Substring(typeStartIndex + 1, typeEndIndex - typeStartIndex - 1)
|
||||
.Trim().ToLower(); // 手动置顶的类型
|
||||
|
||||
// 对象取值表达式
|
||||
parts = expression.Substring(typeEndIndex + 1).Trim().Split(' ');
|
||||
if (parts.Length == 3)
|
||||
{
|
||||
operatorStr = parts[1].ToLower(); // 操作类型
|
||||
valueStr = string.Join(' ', parts.Skip(2)); // 表达式值
|
||||
}
|
||||
else
|
||||
{
|
||||
operatorStr = parts[0].ToLower(); // 操作类型
|
||||
valueStr = string.Join(' ', parts.Skip(1)); // 表达式值
|
||||
}
|
||||
Type? tempType = typeStr switch
|
||||
{
|
||||
"bool" => typeof(bool),
|
||||
"float" => typeof(float),
|
||||
"decimal" => typeof(decimal),
|
||||
"double" => typeof(double),
|
||||
"sbyte" => typeof(sbyte),
|
||||
"byte" => typeof(byte),
|
||||
"short" => typeof(short),
|
||||
"ushort" => typeof(ushort),
|
||||
"int" => typeof(int),
|
||||
"uint" => typeof(uint),
|
||||
"long" => typeof(long),
|
||||
"ulong" => typeof(ulong),
|
||||
"nint" => typeof(nint),
|
||||
"nuint" => typeof(nuint),
|
||||
"string" => typeof(string),
|
||||
_ => Type.GetType(typeStr),
|
||||
};
|
||||
type = tempType ?? throw new ArgumentException("对象表达式无效的类型声明");
|
||||
if (string.IsNullOrWhiteSpace(memberPath))
|
||||
{
|
||||
targetObj = Convert.ChangeType(data, type);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetObj = GetMemberValue(data, memberPath);// 获取对象成员,作为表达式的目标对象
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#region 解析类型 int
|
||||
if (type.IsValueType)
|
||||
{
|
||||
//return GetValueResolver(type, valueStr, operatorStr, parts);
|
||||
}
|
||||
if (type == typeof(int))
|
||||
{
|
||||
var op = ParseValueTypeOperator<int>(operatorStr);
|
||||
if (op == ValueTypeConditionResolver<int>.Operator.InRange || op == ValueTypeConditionResolver<int>.Operator.OutOfRange)
|
||||
{
|
||||
var temp = valueStr.Split('-');
|
||||
if (temp.Length < 2)
|
||||
throw new ArgumentException($"范围无效:{valueStr}。");
|
||||
int rangeStart = int.Parse(temp[0], CultureInfo.InvariantCulture);
|
||||
int rangeEnd = int.Parse(temp[1], CultureInfo.InvariantCulture);
|
||||
return new MemberConditionResolver<int>
|
||||
{
|
||||
Op = op,
|
||||
RangeStart = rangeStart,
|
||||
RangeEnd = rangeEnd,
|
||||
TargetObj = targetObj,
|
||||
ArithmeticExpression = GetArithmeticExpression(parts[0]),
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
int value = int.Parse(valueStr, CultureInfo.InvariantCulture);
|
||||
|
||||
|
||||
return new MemberConditionResolver<int>
|
||||
{
|
||||
TargetObj = targetObj,
|
||||
//MemberPath = memberPath,
|
||||
Op = ParseValueTypeOperator<int>(operatorStr),
|
||||
Value = value,
|
||||
ArithmeticExpression = GetArithmeticExpression(parts[0])
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 解析类型 double
|
||||
else if (type == typeof(double))
|
||||
{
|
||||
double value = double.Parse(valueStr, CultureInfo.InvariantCulture);
|
||||
return new MemberConditionResolver<double>
|
||||
{
|
||||
//MemberPath = memberPath,
|
||||
TargetObj = targetObj,
|
||||
Op = ParseValueTypeOperator<double>(operatorStr),
|
||||
Value = value,
|
||||
ArithmeticExpression = GetArithmeticExpression(parts[0])
|
||||
};
|
||||
|
||||
}
|
||||
#endregion
|
||||
#region 解析类型 bool
|
||||
else if (type == typeof(bool))
|
||||
{
|
||||
return new MemberConditionResolver<bool>
|
||||
{
|
||||
//MemberPath = memberPath,
|
||||
TargetObj = targetObj,
|
||||
Op = (ValueTypeConditionResolver<bool>.Operator)ParseBoolOperator(operatorStr)
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
#region 解析类型 string
|
||||
else if (type == typeof(string))
|
||||
{
|
||||
return new MemberStringConditionResolver
|
||||
{
|
||||
MemberPath = memberPath,
|
||||
Op = ParseStringOperator(operatorStr),
|
||||
Value = valueStr
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
|
||||
throw new NotSupportedException($"Type {type} is not supported.");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 条件表达式解析
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
/// <exception cref="NotSupportedException"></exception>
|
||||
private static SereinConditionResolver ParseSimpleExpression(object data, string expression)
|
||||
{
|
||||
if ("pass".Equals(expression.ToLower()))
|
||||
{
|
||||
return new PassConditionResolver
|
||||
{
|
||||
Op = PassConditionResolver.Operator.Pass,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
if ("not pass".Equals(expression.ToLower()))
|
||||
{
|
||||
return new PassConditionResolver
|
||||
{
|
||||
Op = PassConditionResolver.Operator.NotPass,
|
||||
};
|
||||
}
|
||||
if ("!pass".Equals(expression.ToLower()))
|
||||
{
|
||||
return new PassConditionResolver
|
||||
{
|
||||
Op = PassConditionResolver.Operator.NotPass,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var parts = expression.Split(' ');
|
||||
|
||||
if (parts.Length < 2)
|
||||
throw new ArgumentException("无效的表达式格式。");
|
||||
|
||||
string operatorStr;
|
||||
string valueStr;
|
||||
Type type;
|
||||
// 尝试获取指定类型
|
||||
int typeStartIndex = expression.IndexOf('<');
|
||||
int typeEndIndex = expression.IndexOf('>');
|
||||
if (typeStartIndex + typeStartIndex == -2)
|
||||
{
|
||||
// 如果不需要转为指定类型
|
||||
operatorStr = parts[0];
|
||||
valueStr = string.Join(' ', parts, 1, parts.Length - 1);
|
||||
type = data.GetType();
|
||||
}
|
||||
else
|
||||
{//string typeStr = parts[0];
|
||||
string typeStr = expression.Substring(typeStartIndex + 1, typeEndIndex - typeStartIndex - 1)
|
||||
.Trim().ToLower(); // 手动置顶的类型
|
||||
parts = expression.Substring(typeEndIndex + 1).Trim().Split(' ');
|
||||
operatorStr = parts[0].ToLower(); // 操作类型
|
||||
valueStr = string.Join(' ', parts.Skip(1)); // 表达式值
|
||||
|
||||
|
||||
type = typeStr switch
|
||||
{
|
||||
"bool" => typeof(bool),
|
||||
"float" => typeof(float),
|
||||
"decimal" => typeof(decimal),
|
||||
"double" => typeof(double),
|
||||
"sbyte" => typeof(sbyte),
|
||||
"byte" => typeof(byte),
|
||||
"short" => typeof(short),
|
||||
"ushort" => typeof(ushort),
|
||||
"int" => typeof(int),
|
||||
"uint" => typeof(uint),
|
||||
"long" => typeof(long),
|
||||
"ulong" => typeof(ulong),
|
||||
"nint" => typeof(nint),
|
||||
"nuint" => typeof(nuint),
|
||||
_ => typeof(string),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (type == typeof(bool))
|
||||
{
|
||||
bool value = bool.Parse(valueStr);
|
||||
return new BoolConditionResolver
|
||||
{
|
||||
Op = ParseBoolOperator(operatorStr),
|
||||
Value = value,
|
||||
};
|
||||
}
|
||||
else if (type.IsValueType)
|
||||
{
|
||||
return GetValueResolver(type, valueStr, operatorStr, parts);
|
||||
}
|
||||
else if (type == typeof(string))
|
||||
{
|
||||
return new StringConditionResolver
|
||||
{
|
||||
Op = ParseStringOperator(operatorStr),
|
||||
Value = valueStr
|
||||
};
|
||||
}
|
||||
|
||||
throw new NotSupportedException($"Type {type} is not supported.");
|
||||
}
|
||||
|
||||
public static SereinConditionResolver GetValueResolver(Type valueType, string valueStr, string operatorStr, string[] parts)// where T : struct, IComparable<T>
|
||||
{
|
||||
SereinConditionResolver resolver = valueType switch
|
||||
{
|
||||
Type t when t == typeof(float) => GetValueResolver<float>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(decimal) => GetValueResolver<decimal>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(double) => GetValueResolver<double>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(sbyte) => GetValueResolver<sbyte>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(byte) => GetValueResolver<byte>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(short) => GetValueResolver<short>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(ushort) => GetValueResolver<ushort>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(int) => GetValueResolver<int>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(uint) => GetValueResolver<uint>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(long) => GetValueResolver<long>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(ulong) => GetValueResolver<ulong>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(nint) => GetValueResolver<nint>(valueStr, operatorStr, parts),
|
||||
Type t when t == typeof(nuint) => GetValueResolver<nuint>(valueStr, operatorStr, parts),
|
||||
_ => throw new ArgumentException("非预期值类型")
|
||||
};
|
||||
return resolver;
|
||||
}
|
||||
|
||||
|
||||
private static ValueTypeConditionResolver<T> GetValueResolver<T>(string valueStr, string operatorStr, string[] parts)
|
||||
where T :struct, IComparable<T>
|
||||
{
|
||||
var op = ParseValueTypeOperator<T>(operatorStr);
|
||||
if (op == ValueTypeConditionResolver<T>.Operator.InRange || op == ValueTypeConditionResolver<T>.Operator.OutOfRange)
|
||||
{
|
||||
var temp = valueStr.Split('-');
|
||||
var leftNum = string.Empty;
|
||||
var rightNum = string.Empty;
|
||||
if (temp.Length < 2 || temp.Length > 4)
|
||||
{
|
||||
throw new ArgumentException($"范围无效:{valueStr}。");
|
||||
}
|
||||
else if (temp.Length == 2)
|
||||
{
|
||||
leftNum = temp[0];
|
||||
rightNum = temp[1];
|
||||
}
|
||||
else if (temp.Length == 3)
|
||||
{
|
||||
if (string.IsNullOrEmpty(temp[0])
|
||||
&& !string.IsNullOrEmpty(temp[1])
|
||||
&& !string.IsNullOrEmpty(temp[2]))
|
||||
{
|
||||
leftNum = "-" + temp[1];
|
||||
rightNum = temp[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"范围无效:{valueStr}。");
|
||||
}
|
||||
}
|
||||
else if (temp.Length == 4)
|
||||
{
|
||||
if (string.IsNullOrEmpty(temp[0])
|
||||
&& !string.IsNullOrEmpty(temp[1])
|
||||
&& string.IsNullOrEmpty(temp[2])
|
||||
&& !string.IsNullOrEmpty(temp[3]))
|
||||
{
|
||||
leftNum = "-" + temp[1];
|
||||
rightNum = temp[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"范围无效:{valueStr}。");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return new ValueTypeConditionResolver<T>
|
||||
{
|
||||
Op = op,
|
||||
RangeStart = leftNum.ToValueData<T>(),
|
||||
RangeEnd = rightNum.ToValueData<T>(),
|
||||
ArithmeticExpression = GetArithmeticExpression(parts[0]),
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ValueTypeConditionResolver<T>
|
||||
{
|
||||
Op = op,
|
||||
Value = valueStr.ToValueData<T>(),
|
||||
ArithmeticExpression = GetArithmeticExpression(parts[0])
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
//public static T ValueParse<T>(object value) where T : struct, IComparable<T>
|
||||
//{
|
||||
// return (T)ValueParse(typeof(T), value);
|
||||
//}
|
||||
|
||||
//public static object ValueParse(Type type, object value)
|
||||
//{
|
||||
|
||||
// string? valueStr = value.ToString();
|
||||
// if (string.IsNullOrEmpty(valueStr))
|
||||
// {
|
||||
// throw new ArgumentException("value is null");
|
||||
// }
|
||||
// object result = type switch
|
||||
// {
|
||||
// Type t when t.IsEnum => Enum.Parse(type, valueStr),
|
||||
// Type t when t == typeof(bool) => bool.Parse(valueStr),
|
||||
// Type t when t == typeof(float) => float.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(decimal) => decimal.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(double) => double.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(sbyte) => sbyte.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(byte) => byte.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(short) => short.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(ushort) => ushort.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(int) => int.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(uint) => uint.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(long) => long.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(ulong) => ulong.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(nint) => nint.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// Type t when t == typeof(nuint) => nuint.Parse(valueStr, CultureInfo.InvariantCulture),
|
||||
// _ => throw new ArgumentException("非预期值类型")
|
||||
// };
|
||||
// return result;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 数值操作类型
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="operatorStr"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private static ValueTypeConditionResolver<T>.Operator ParseValueTypeOperator<T>(string operatorStr) where T : struct, IComparable<T>
|
||||
{
|
||||
return operatorStr switch
|
||||
{
|
||||
">" => ValueTypeConditionResolver<T>.Operator.GreaterThan,
|
||||
"<" => ValueTypeConditionResolver<T>.Operator.LessThan,
|
||||
"==" => ValueTypeConditionResolver<T>.Operator.Equal,
|
||||
">=" or "≥" => ValueTypeConditionResolver<T>.Operator.GreaterThanOrEqual,
|
||||
"<=" or "≤" => ValueTypeConditionResolver<T>.Operator.LessThanOrEqual,
|
||||
"in" => ValueTypeConditionResolver<T>.Operator.InRange,
|
||||
"!in" => ValueTypeConditionResolver<T>.Operator.OutOfRange,
|
||||
_ => throw new ArgumentException($"Invalid operator {operatorStr} for value type.")
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 布尔操作类型
|
||||
/// </summary>
|
||||
/// <param name="operatorStr"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private static BoolConditionResolver.Operator ParseBoolOperator(string operatorStr)
|
||||
{
|
||||
return operatorStr switch
|
||||
{
|
||||
"is" or "==" or "equals" => BoolConditionResolver.Operator.Is,
|
||||
_ => throw new ArgumentException($"Invalid operator {operatorStr} for bool type.")
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 字符串操作类型
|
||||
/// </summary>
|
||||
/// <param name="operatorStr"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private static StringConditionResolver.Operator ParseStringOperator(string operatorStr)
|
||||
{
|
||||
return operatorStr.ToLower() switch
|
||||
{
|
||||
"c" or "contains" => StringConditionResolver.Operator.Contains,
|
||||
"nc" or "doesnotcontain" => StringConditionResolver.Operator.DoesNotContain,
|
||||
"sw" or "startswith" => StringConditionResolver.Operator.StartsWith,
|
||||
"ew" or "endswith" => StringConditionResolver.Operator.EndsWith,
|
||||
|
||||
"==" or "equals" => StringConditionResolver.Operator.Equal,
|
||||
"!=" or "notequals" => StringConditionResolver.Operator.NotEqual,
|
||||
|
||||
_ => throw new ArgumentException($"Invalid operator {operatorStr} for string type.")
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression
|
||||
{
|
||||
/// <summary>
|
||||
/// 条件解析抽象类
|
||||
/// </summary>
|
||||
public abstract class SereinConditionResolver
|
||||
{
|
||||
public abstract bool Evaluate(object obj);
|
||||
}
|
||||
}
|
||||
@@ -1,361 +0,0 @@
|
||||
using Serein.Library.Utils;
|
||||
using System.Data;
|
||||
|
||||
namespace Serein.NodeFlow.Tool.SereinExpression
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用表达式操作/获取 对象的值
|
||||
/// 获取值 @get .xx.xxx
|
||||
/// 设置值 @set .xx.xxx = [data]
|
||||
/// </summary>
|
||||
/// <param name="obj">操作的对象</param>
|
||||
/// <returns></returns>
|
||||
public class SerinArithmeticExpressionEvaluator<T> where T : struct, IComparable<T>
|
||||
{
|
||||
private static readonly DataTable table = new DataTable();
|
||||
|
||||
public static T Evaluate(string expression, T inputValue)
|
||||
{
|
||||
|
||||
// 替换占位符@为输入值
|
||||
expression = expression.Replace("@", inputValue.ToString());
|
||||
try
|
||||
{
|
||||
// 使用 DataTable.Compute 方法计算表达式
|
||||
var result = table.Compute(expression, string.Empty);
|
||||
return (T)result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw new ArgumentException("Invalid arithmetic expression.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class SerinExpressionEvaluator
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="expression">表达式</param>
|
||||
/// <param name="targetObJ">操作对象</param>
|
||||
/// <param name="isChange">是否改变了对象(Set语法)</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
/// <exception cref="NotSupportedException"></exception>
|
||||
public static object? Evaluate(string expression, object targetObJ, out bool isChange)
|
||||
{
|
||||
var parts = expression.Split([' '], 2);
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
throw new ArgumentException("Invalid expression format.");
|
||||
}
|
||||
|
||||
var operation = parts[0].ToLower();
|
||||
var operand = parts[1][0] == '.' ? parts[1][1..] : parts[1];
|
||||
|
||||
var result = operation switch
|
||||
{
|
||||
"@num" => ComputedNumber(targetObJ, operand),
|
||||
"@call" => InvokeMethod(targetObJ, operand),
|
||||
"@get" => GetMember(targetObJ, operand),
|
||||
"@set" => SetMember(targetObJ, operand),
|
||||
_ => throw new NotSupportedException($"Operation {operation} is not supported.")
|
||||
};
|
||||
|
||||
isChange = operation switch
|
||||
{
|
||||
/*"@num" => true,
|
||||
"@call" => true,
|
||||
"@get" => true,*/
|
||||
"@set" => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private static readonly char[] separator = ['(', ')'];
|
||||
private static readonly char[] separatorArray = [','];
|
||||
|
||||
/// <summary>
|
||||
/// 调用目标方法
|
||||
/// </summary>
|
||||
/// <param name="target">目标实例</param>
|
||||
/// <param name="methodCall">方法名称</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private static object? InvokeMethod(object? target, string methodCall)
|
||||
{
|
||||
if (target is null) return null;
|
||||
var methodParts = methodCall.Split(separator, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (methodParts.Length != 2)
|
||||
{
|
||||
throw new ArgumentException("Invalid method call format.");
|
||||
}
|
||||
|
||||
var methodName = methodParts[0];
|
||||
var parameterList = methodParts[1];
|
||||
var parameters = parameterList.Split(separatorArray, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(p => p.Trim())
|
||||
.ToArray();
|
||||
|
||||
var method = target.GetType().GetMethod(methodName) ?? throw new ArgumentException($"Method {methodName} not found on target.");
|
||||
var parameterValues = method.GetParameters()
|
||||
.Select((p, index) => Convert.ChangeType(parameters[index], p.ParameterType))
|
||||
.ToArray();
|
||||
|
||||
|
||||
return method.Invoke(target, parameterValues);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取值
|
||||
/// </summary>
|
||||
/// <param name="target">目标实例</param>
|
||||
/// <param name="memberPath">属性路径</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private static object? GetMember(object? target, string memberPath)
|
||||
{
|
||||
if (target is null) return null;
|
||||
// 分割成员路径,按 '.' 处理多级访问
|
||||
var members = memberPath.Split('.');
|
||||
|
||||
foreach (var member in members)
|
||||
{
|
||||
// 检查成员是否包含数组索引,例如 "cars[0]"
|
||||
var arrayIndexStart = member.IndexOf('[');
|
||||
if (arrayIndexStart != -1)
|
||||
{
|
||||
// 解析数组/集合名与索引部分
|
||||
var arrayName = member.Substring(0, arrayIndexStart);
|
||||
var arrayIndexEnd = member.IndexOf(']');
|
||||
if (arrayIndexEnd == -1 || arrayIndexEnd <= arrayIndexStart + 1)
|
||||
{
|
||||
throw new ArgumentException($"Invalid array syntax for member {member}");
|
||||
}
|
||||
|
||||
// 提取数组索引
|
||||
var indexStr = member.Substring(arrayIndexStart + 1, arrayIndexEnd - arrayIndexStart - 1);
|
||||
if (!int.TryParse(indexStr, out int index))
|
||||
{
|
||||
throw new ArgumentException($"Invalid array index '{indexStr}' for member {member}");
|
||||
}
|
||||
|
||||
// 获取数组或集合对象
|
||||
var arrayProperty = target?.GetType().GetProperty(arrayName);
|
||||
if (arrayProperty is null)
|
||||
{
|
||||
var arrayField = target?.GetType().GetField(arrayName);
|
||||
if (arrayField is null)
|
||||
{
|
||||
throw new ArgumentException($"Member {arrayName} not found on target.");
|
||||
}
|
||||
else
|
||||
{
|
||||
target = arrayField.GetValue(target);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
target = arrayProperty.GetValue(target);
|
||||
}
|
||||
|
||||
// 访问数组或集合中的指定索引
|
||||
if (target is Array array)
|
||||
{
|
||||
if (index < 0 || index >= array.Length)
|
||||
{
|
||||
throw new ArgumentException($"Index {index} out of bounds for array {arrayName}");
|
||||
}
|
||||
target = array.GetValue(index);
|
||||
}
|
||||
else if (target is IList<object> list)
|
||||
{
|
||||
if (index < 0 || index >= list.Count)
|
||||
{
|
||||
throw new ArgumentException($"Index {index} out of bounds for list {arrayName}");
|
||||
}
|
||||
target = list[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"Member {arrayName} is not an array or list.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理非数组情况的属性或字段
|
||||
var property = target?.GetType().GetProperty(member);
|
||||
if (property is null)
|
||||
{
|
||||
var field = target?.GetType().GetField(member);
|
||||
if (field is null)
|
||||
{
|
||||
throw new ArgumentException($"Member {member} not found on target.");
|
||||
}
|
||||
else
|
||||
{
|
||||
target = field.GetValue(target);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
target = property.GetValue(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置目标的值
|
||||
/// </summary>
|
||||
/// <param name="target">目标实例</param>
|
||||
/// <param name="assignment">属性路径 </param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="ArgumentException"></exception>
|
||||
private static object? SetMember(object? target, string assignment)
|
||||
{
|
||||
var parts = assignment.Split(new[] { '=' }, 2);
|
||||
if (parts.Length != 2)
|
||||
{
|
||||
throw new ArgumentException("Invalid assignment format.");
|
||||
}
|
||||
|
||||
var memberPath = parts[0].Trim();
|
||||
var value = parts[1].Trim();
|
||||
|
||||
var members = memberPath.Split('.');
|
||||
for (int i = 0; i < members.Length - 1; i++)
|
||||
{
|
||||
var member = members[i];
|
||||
|
||||
// 检查是否包含数组索引
|
||||
var arrayIndexStart = member.IndexOf('[');
|
||||
if (arrayIndexStart != -1)
|
||||
{
|
||||
// 解析数组名和索引
|
||||
var arrayName = member.Substring(0, arrayIndexStart);
|
||||
var arrayIndexEnd = member.IndexOf(']');
|
||||
if (arrayIndexEnd == -1 || arrayIndexEnd <= arrayIndexStart + 1)
|
||||
{
|
||||
throw new ArgumentException($"Invalid array syntax for member {member}");
|
||||
}
|
||||
|
||||
var indexStr = member.Substring(arrayIndexStart + 1, arrayIndexEnd - arrayIndexStart - 1);
|
||||
if (!int.TryParse(indexStr, out int index))
|
||||
{
|
||||
throw new ArgumentException($"Invalid array index '{indexStr}' for member {member}");
|
||||
}
|
||||
|
||||
// 获取数组或集合
|
||||
var arrayProperty = target?.GetType().GetProperty(arrayName);
|
||||
if (arrayProperty is null)
|
||||
{
|
||||
var arrayField = target?.GetType().GetField(arrayName);
|
||||
if (arrayField is null)
|
||||
{
|
||||
throw new ArgumentException($"Member {arrayName} not found on target.");
|
||||
}
|
||||
else
|
||||
{
|
||||
target = arrayField.GetValue(target);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
target = arrayProperty.GetValue(target);
|
||||
}
|
||||
|
||||
// 获取目标数组或集合中的指定元素
|
||||
if (target is Array array)
|
||||
{
|
||||
if (index < 0 || index >= array.Length)
|
||||
{
|
||||
throw new ArgumentException($"Index {index} out of bounds for array {arrayName}");
|
||||
}
|
||||
target = array.GetValue(index);
|
||||
}
|
||||
else if (target is IList<object> list)
|
||||
{
|
||||
if (index < 0 || index >= list.Count)
|
||||
{
|
||||
throw new ArgumentException($"Index {index} out of bounds for list {arrayName}");
|
||||
}
|
||||
target = list[index];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"Member {arrayName} is not an array or list.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理非数组情况的属性或字段
|
||||
var property = target?.GetType().GetProperty(member);
|
||||
if (property is null)
|
||||
{
|
||||
var field = target?.GetType().GetField(member);
|
||||
if (field is null)
|
||||
{
|
||||
throw new ArgumentException($"Member {member} not found on target.");
|
||||
}
|
||||
else
|
||||
{
|
||||
target = field.GetValue(target);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
target = property.GetValue(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 设置值
|
||||
var lastMember = members.Last();
|
||||
|
||||
var lastProperty = target?.GetType().GetProperty(lastMember);
|
||||
if (lastProperty is null)
|
||||
{
|
||||
var lastField = target?.GetType().GetField(lastMember);
|
||||
if (lastField is null)
|
||||
{
|
||||
throw new ArgumentException($"Member {lastMember} not found on target.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var convertedValue = Convert.ChangeType(value, lastField.FieldType);
|
||||
lastField.SetValue(target, convertedValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var convertedValue = Convert.ChangeType(value, lastProperty.PropertyType);
|
||||
lastProperty.SetValue(target, convertedValue);
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
/// <summary>
|
||||
/// 计算数学简单表达式
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="expression"></param>
|
||||
/// <returns></returns>
|
||||
private static decimal ComputedNumber(object value, string expression)
|
||||
{
|
||||
return ComputedNumber<decimal>(value, expression);
|
||||
}
|
||||
|
||||
private static T ComputedNumber<T>(object value, string expression) where T : struct, IComparable<T>
|
||||
{
|
||||
T result = value.ToConvert<T>();
|
||||
return SerinArithmeticExpressionEvaluator<T>.Evaluate(expression, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user