1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00
Robert 7eadc58bee Nodes - Added node type registration system
Nodes - Moved models and node logic into core
Nodes - Added node service that leverages DI
2021-08-07 21:05:15 +02:00

81 lines
1.8 KiB
C#

using System;
namespace Artemis.Core
{
public sealed class OutputPin<T> : Pin
{
#region Properties & Fields
public override Type Type { get; } = typeof(T);
public override object PinValue => Value;
public override PinDirection Direction => PinDirection.Output;
private T _value;
public T Value
{
get
{
if (!IsEvaluated)
Node?.Evaluate();
return _value;
}
set
{
_value = value;
IsEvaluated = true;
}
}
#endregion
#region Constructors
internal OutputPin(INode node, string name)
: base(node, name)
{ }
#endregion
}
public sealed class OutputPin : Pin
{
#region Properties & Fields
public override Type Type { get; }
public override object PinValue => Value;
public override PinDirection Direction => PinDirection.Output;
private object _value;
public object Value
{
get
{
if (!IsEvaluated)
Node?.Evaluate();
return _value;
}
set
{
if (!Type.IsInstanceOfType(value)) throw new ArgumentException($"Value of type '{value?.GetType().Name ?? "null"}' can't be assigned to a pin of type {Type.Name}.");
_value = value;
IsEvaluated = true;
}
}
#endregion
#region Constructors
internal OutputPin(INode node, Type type, string name)
: base(node, name)
{
this.Type = type;
}
#endregion
}
}