Cast


Node Information
Cast one type to the other.
General Information
• This node has other options, you can view them by clicking on the info button, this also means according to the node you might be able to add more ports than what is already listed.
Visual
Visual

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

Source
namespace Korduene.KGraph.Nodes.Types
{
    [IsNode("Cast")]
    public class Cast : Node
    {
        Port from = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "From");
        Port to = new Port(PortType.OUT, typeof(object), AcceptsLinks.MULTIPLE, "To");
        bool isFrom = false;
        public Cast()
        {
            Name = "Cast";
            AddPort(from);
            AddPort(to);
            from.EditorEnabled = false;
            OptionsAvilable = true;
            InfoContextMenu = new System.Windows.Controls.ContextMenu();
            System.Windows.Controls.MenuItem fromtype = new System.Windows.Controls.MenuItem();
            System.Windows.Controls.MenuItem totype = new System.Windows.Controls.MenuItem();
            fromtype.Header = "From";
            totype.Header = "To";
            InfoContextMenu.Items.Add(fromtype);
            InfoContextMenu.Items.Add(totype);
            Information = "Cast one type to the other.";
            fromtype.Click += fromtype_Click;
            totype.Click += totype_Click;
        }
        void fromtype_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            isFrom = true;
            OpenTypeSelectionMenu(false, false);
        }
        void totype_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            isFrom = false;
            OpenTypeSelectionMenu(false, false);
        }
        public override void OnTypeSelected(Type type)
        {
            if (isFrom)
            {
                from.DataType = type;
            }
            else
            {
                to.DataType = type;
            }
            to.Instructions = "((" + GraphCore.GetFullTypeName(to.DataType) + ")" + GetValue(from) + ")";
        }
        public override void UpdateResults()
        {
            to.Instructions = "((" + GraphCore.GetFullTypeName(to.DataType) + ")" + GetValue(from) + ")";
        }
    }
}