using Serein.Library.Api; using System; using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; using System.Text; namespace Serein.Library { /// /// 节点入参参数详情 /// [NodeProperty(ValuePath = NodeValuePath.Parameter)] public partial class ParameterDetails { private readonly IFlowEnvironment env; private readonly NodeModelBase nodeModel; /// /// 参数索引 /// [PropertyInfo] private int _index; /// /// 是否为显式参数(固定值/表达式) /// [PropertyInfo(IsNotification = true)] private bool _isExplicitData ; /// /// 转换器 IEnumConvertor<,> /// [PropertyInfo] private Func _convertor ; /// /// 显式类型 /// [PropertyInfo] private Type _explicitType ; /// /// 目前存在三种状态:Select/Bool/Value /// Select : 枚举值 /// Bool : 布尔类型 /// Value : 除以上类型之外的任意参数 /// [PropertyInfo] private string _explicitTypeName ; /// /// 方法需要的类型 /// [PropertyInfo] private Type _dataType ; /// /// 方法入参参数名称 /// [PropertyInfo] private string _name ; /// /// 自定义的方法入参数据 /// [PropertyInfo(IsNotification = true)] // IsPrint = true private string _dataValue; /// /// 如果是引用类型,拷贝时不会发生改变。 /// [PropertyInfo(IsNotification = true)] private string[] _items ; } public partial class ParameterDetails { /// /// 为节点实例化新的入参描述 /// public ParameterDetails(IFlowEnvironment env, NodeModelBase nodeModel) { this.env = env; this.nodeModel = nodeModel; } /// /// 通过参数信息加载实体,用于加载项目文件、远程连接的场景 /// /// 参数信息 public ParameterDetails(ParameterDetailsInfo info) { //this.env = env; Index = info.Index; Name = info.Name; DataType = Type.GetType(info.DataTypeFullName); ExplicitType = Type.GetType(info.ExplicitTypeFullName); ExplicitTypeName = info.ExplicitTypeName; Items = info.Items; } /// /// 用于创建元数据 /// /// 方法参数信息 public ParameterDetails() { } /// /// 转为描述 /// /// public ParameterDetailsInfo ToInfo() { return new ParameterDetailsInfo { Index = Index, DataTypeFullName = DataType.FullName, Name = Name, ExplicitTypeFullName = ExplicitType.FullName, ExplicitTypeName = ExplicitTypeName, Items = Items, }; } /// /// 为某个节点拷贝方法描述的入参描述 /// /// 运行环境 /// 运行环境 /// public ParameterDetails CloneOfClone(IFlowEnvironment env, NodeModelBase nodeModel) { var pd = new ParameterDetails(env, nodeModel) { Index = this.Index, IsExplicitData = this.IsExplicitData, ExplicitType = this.ExplicitType, ExplicitTypeName = this.ExplicitTypeName, Convertor = this.Convertor, DataType = this.DataType, Name = this.Name, DataValue = string.IsNullOrEmpty(DataValue) ? string.Empty : DataValue, Items = this.Items?.Select(it => it).ToArray(), }; return pd; } } ///// ///// 节点入参参数详情 ///// //public partial class TempParameterDetails //{ // private readonly MethodDetails methodDetails; // /// // /// 参数索引 // /// // public int Index { get; set; } // /// // /// 是否为显式参数(固定值/表达式) // /// // public bool IsExplicitData { get; set; } // /// // /// 转换器 IEnumConvertor<,> // /// // public Func Convertor { get; set; } // /// // /// 显式类型 // /// // public Type ExplicitType { get; set; } // /// // /// 目前存在三种状态:Select/Bool/Value // /// Select : 枚举值 // /// Bool : 布尔类型 // /// Value : 除以上类型之外的任意参数 // /// // public string ExplicitTypeName { get; set; } // /// // /// 方法需要的类型 // /// // public Type DataType { get; set; } // /// // /// 方法入参参数名称 // /// // public string Name { get; set; } // private string _dataValue; // /// // /// 入参值(在UI上输入的文本内容) // /// // public string DataValue // { // get => _dataValue; set // { // _dataValue = value; // Console.WriteLine($"更改了{value}"); // } // } // /// // /// 如果是引用类型,拷贝时不会发生改变。 // /// // public string[] Items { get; set; } //} }