NodePipeline/NodePipeline.Engine.Abstractions/Validation/NodePortKey.cs
2026-01-02 20:55:25 +03:00

51 lines
1.4 KiB
C#

using System;
// ReSharper disable MemberCanBePrivate.Global
namespace NodePipeline.Engine.Abstractions.Validation;
public readonly struct NodePortKey(string nodeType, string portName, bool input) : IEquatable<NodePortKey>
{
public string NodeType { get; } = nodeType;
public string PortName { get; } = portName;
public bool Input { get; } = input;
public bool Equals(NodePortKey other)
{
return string.Equals(NodeType, other.NodeType, StringComparison.Ordinal) &&
string.Equals(PortName, other.PortName, StringComparison.Ordinal) &&
Input == other.Input;
}
public override bool Equals(object? obj)
{
return obj is NodePortKey other && Equals(other);
}
public override int GetHashCode()
{
unchecked
{
var hash = 17;
hash = hash * 23 + (NodeType?.GetHashCode() ?? 0);
hash = hash * 23 + (PortName?.GetHashCode() ?? 0);
hash = hash * 23 + Input.GetHashCode();
return hash;
}
}
public static bool operator ==(NodePortKey left, NodePortKey right)
{
return left.Equals(right);
}
public static bool operator !=(NodePortKey left, NodePortKey right)
{
return !left.Equals(right);
}
public override string ToString()
{
return $"{NodeType}:{PortName}:{(Input ? "In" : "Out")}";
}
}