using System;
using NodePipeline.Abstractions.Interfaces.Nodes;
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable UnusedType.Global
#pragma warning disable CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).
namespace NodePipeline.Abstractions.Models;
///
/// Node field class
/// Wraps value and can be a port with Input or Output direction or a Parameter.
///
///
public class NodeField : INodeField
{
private Func? _getter;
private Action? _setter;
private T _value = default!;
///
/// Node field name
///
public string Name { get; set; } = string.Empty;
///
/// Node field description
///
public string? Description { get; set; }
///
/// Node field code (with node id)
///
public string Code { get; set; } = string.Empty;
///
/// Node field direction
///
/// Port directions: Input, Output
///
/// Parameter: Parameter
///
///
public FieldDirection Direction { get; set; }
///
/// Node field value
///
public T Value
{
get => _getter != null ? _getter() : _value;
set
{
if (_setter != null) _setter(value);
else _value = value;
}
}
///
/// Static binding (during pipeline building)
///
///
public void BindStatic(INodeField outputPort)
{
_getter = () => outputPort.Value;
_setter = v => outputPort.Value = v;
}
///
/// Runtime binding (during pipeline Execution)
///
///
///
public void BindRuntime(Func getter, Action? setter)
{
_getter = getter;
_setter = setter ?? (_ => { });
}
}
#pragma warning restore CS8766 // Nullability of reference types in return type doesn't match implicitly implemented member (possibly because of nullability attributes).