Auto Cast


Node Information
Automatically cast one type to the other.
General Information
• This node doesn't have other available options.
• Some of the ports of this node can change their types and accept types automatically.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
From IN Object ONE FALSE TRUE
To OUT Object MULTIPLE FALSE TRUE

Source
namespace Korduene.KGraph.Nodes.Types
{
    [IsNode("Auto Cast")]
    public class AutoCast : Node
    {
        Port from = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "From");
        Port to = new Port(PortType.OUT, typeof(object), AcceptsLinks.MULTIPLE, "To");
        public AutoCast()
        {
            Name = "Auto Cast";
            AddPort(from);
            AddPort(to);
            from.CustomAcception = FromAccepts;
            to.CustomAcception = ToAccepts;
            Information = "Automatically cast one type to the other.";
        }
        bool FromAccepts(Port port)
        {
            if (from.IsConnected)
            {
                return false;
            }
            from.DataType = port.DataType;
            SetInstructions();
            return true;
        }
        bool ToAccepts(Port port)
        {
            if (to.IsConnected)
            {
                return false;
            }
            to.DataType = port.DataType;
            SetInstructions();
            return true;
        }
        private void SetInstructions()
        {
            to.Instructions = "((" + GraphCore.GetFullTypeName(to.DataType) + ")" + GetValue(from) + ")";
        }
        public override void UpdateResults()
        {
            SetInstructions();
        }
    }
}