using Serein.Library.Api;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Text;
using System.Threading.Tasks;
namespace Serein.Library
{
///
/// 表示空数据
///
/*public readonly struct Unit : IEquatable
{
public static readonly Unit Default = default;
public bool Equals(Unit _) => true;
public override bool Equals(object obj) => obj is Unit;
public override int GetHashCode() => 0;
}*/
///
/// 流程返回值的包装
///
public class FlowResult
{
///
/// 实例化返回值
///
///
///
public FlowResult(IFlowNode nodeModel, IDynamicContext context, object value)
{
this.NodeGuid = nodeModel.Guid;
this.ContextGuid = context.Guid;
this.Value = value;
}
///
/// 空返回值
///
///
///
public FlowResult(IFlowNode nodeModel, IDynamicContext context)
{
this.NodeGuid = nodeModel.Guid;
this.ContextGuid = context.Guid;
this.Value = Unit.Default;
}
///
/// 尝试获取值
///
/// 目标类型
/// 返回值
/// 指示是否获取成功
/// 无法转为对应类型
public bool TryGetValue(Type targetType, out object value)
{
if (targetType is null)
throw new ArgumentNullException(nameof(targetType));
if (targetType.IsInstanceOfType(Value))
{
value = Value;
return true;
}
value = Unit.Default;
return false;
}
///
/// 来源节点Guid
///
public string NodeGuid { get; }
///
/// 来源上下文Guid
///
public string ContextGuid { get; }
///
/// 数据值
///
public object Value { get; private set; }
///
/// 生成时间
///
public DateTime ResultTime { get; } = DateTime.MinValue;
///
/// 是否自动回收
///
public bool IsAutoRecovery { get; set; }
}
}