using Serein.Library.Api;
using Serein.Library.Utils;
using System;
using System.Linq;
using System.Text;
namespace Serein.Library
{
///
/// 每个节点有独自的MethodDetails实例
///
[NodeProperty(ValuePath = NodeValuePath.Method)]
public partial class MethodDetails
{
// private readonly IFlowEnvironment env;
///
/// 对应的节点
///
[PropertyInfo(IsProtection = true)]
private NodeModelBase _nodeModel;
///
/// 是否保护参数(目前仅视觉效果参数,不影响运行实现,后续将设置作用在运行逻辑中)
///
[PropertyInfo(IsNotification = true)]
private bool _isProtectionParameter;
///
/// 作用实例的类型(多个相同的节点将拥有相同的类型)
///
[PropertyInfo]
private Type _actingInstanceType;
///
/// 作用实例(多个相同的节点将会共享同一个实例)
///
[PropertyInfo]
private object _actingInstance;
///
/// 方法名称
///
[PropertyInfo]
private string _methodName;
///
/// 节点类型
///
[PropertyInfo]
private NodeType _methodDynamicType;
///
/// 锁名称(暂未实现)
///
[PropertyInfo]
private string _methodLockName;
///
/// 方法别名
///
[PropertyInfo]
private string _methodAnotherName;
///
/// 参数描述
///
[PropertyInfo]
private ParameterDetails[] _parameterDetailss;
///
/// 出参类型
///
[PropertyInfo]
private Type _returnType;
}
public partial class MethodDetails
{
///
/// 不包含方法信息的基础节点(后续可能要改为DLL引入基础节点)
///
public MethodDetails()
{
}
///
/// 生成元数据
///
/// 节点运行的环境
/// 标识属于哪个节点
public MethodDetails(IFlowEnvironment env, NodeModelBase nodeModel)
{
NodeModel = nodeModel;
}
///
/// 从方法信息中读取
///
///
public MethodDetails(MethodDetailsInfo Info)
{
if (!Info.NodeType.TryConvertEnum(out var nodeType))
{
throw new ArgumentException("无效的节点类型");
}
MethodName = Info.MethodName;
MethodAnotherName = Info.MethodAnotherName;
MethodDynamicType = nodeType;
ReturnType = Type.GetType(Info.ReturnTypeFullName);
ParameterDetailss = Info.ParameterDetailsInfos.Select(pinfo => new ParameterDetails(pinfo)).ToArray();
}
///
/// 转为信息
///
///
public MethodDetailsInfo ToInfo()
{
return new MethodDetailsInfo
{
MethodName = MethodName,
MethodAnotherName = MethodAnotherName,
NodeType = MethodDynamicType.ToString(),
ParameterDetailsInfos = ParameterDetailss.Select(p => p.ToInfo()).ToArray(),
ReturnTypeFullName = ReturnType.FullName,
};
}
///
/// 从DLL拖动出来时拷贝属于节点的实例
///
///
public MethodDetails CloneOfNode(IFlowEnvironment env, NodeModelBase nodeModel)
{
var md = new MethodDetails(env, nodeModel) // 创建新节点时拷贝实例
{
ActingInstance = this.ActingInstance,
ActingInstanceType = this.ActingInstanceType,
MethodDynamicType = this.MethodDynamicType,
MethodAnotherName = this.MethodAnotherName,
ReturnType = this.ReturnType,
MethodName = this.MethodName,
MethodLockName = this.MethodLockName,
IsProtectionParameter = this.IsProtectionParameter,
};
md.ParameterDetailss = this.ParameterDetailss?.Select(p => p?.CloneOfClone(env, nodeModel)).ToArray(); // 拷贝属于节点方法的新入参描述
return md;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine($"方法别名:{this.MethodAnotherName}");
sb.AppendLine($"方法名称:{this.MethodName}");
sb.AppendLine($"需要实例:{this.ActingInstanceType?.FullName}");
sb.AppendLine($"");
sb.AppendLine($"入参参数信息:");
foreach (var arg in this.ParameterDetailss)
{
sb.AppendLine($" {arg.ToString()}");
}
sb.AppendLine($"");
sb.AppendLine($"返回值信息:");
sb.AppendLine($" {this.ReturnType.FullName}");
return sb.ToString();
}
/////
///// 每个节点有独自的MethodDetails实例
/////
//public partial class TmpMethodDetails
//{
// ///
// /// 是否保护参数(目前仅视觉效果参数,不影响运行实现,后续将设置作用在运行逻辑中)
// ///
// public bool IsProtectionParameter { get; set; } = false;
// ///
// /// 作用实例的类型(多个相同的节点将拥有相同的类型)
// ///
// public Type ActingInstanceType { get; set; }
// ///
// /// 作用实例(多个相同的节点将会共享同一个实例)
// ///
// public object ActingInstance { get; set; }
// ///
// /// 方法名称
// ///
// public string MethodName { get; set; }
// ///
// /// 节点类型
// ///
// public NodeType MethodDynamicType { get; set; }
// ///
// /// 锁名称(暂未实现)
// ///
// public string MethodLockName { get; set; }
// ///
// /// 方法说明
// ///
// public string MethodTips { get; set; }
// ///
// /// 参数描述
// ///
// public ParameterDetails[] ParameterDetailss { get; set; }
// ///
// /// 出参类型
// ///
// public Type ReturnType { get; set; }
//}
}
}