Convert


Node Information
Converts list to a list of a specified type.
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
List IN List<Object> ONE TRUE TRUE
Value OUT List<String> MULTIPLE TRUE FALSE

Source
namespace Korduene.KGraph.Nodes.List
{
    [IsNode("Convert")]
    public class ListConvert : Node
    {
        Port list = new Port(PortType.IN, typeof(List<object>), AcceptsLinks.ONE, "List");
        Port get = new Port(PortType.OUT, typeof(List<string>), AcceptsLinks.MULTIPLE, "Value");
        System.Windows.Controls.MenuItem pr = new System.Windows.Controls.MenuItem();
        public ListConvert()
        {
            this.Name = "Convert";
            AddPort(list);
            AddPort(get);
            list.CustomAcception = Accepts;
            InfoContextMenu = new System.Windows.Controls.ContextMenu();
            System.Windows.Controls.MenuItem result = new System.Windows.Controls.MenuItem();
            result.Header = "Out Type";
            InfoContextMenu.Items.Add(result);
            InfoContextMenu.Items.Add(pr);
            result.Click += result_Click;
            pr.Header = "Property";
            get.Instructions = "init";
            Information = "Converts list to a list of a specified type.";
        }
        void result_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            OpenTypeSelectionMenu(false, false);
        }
        public override void OnTypeSelected(Type type)
        {
            get.DataType = type.MakeGenericType(typeof(List<>));
            GetProperties();
        }
        public override void OnTypePropertySelected(System.Reflection.PropertyInfo opi)
        {
            list.Value = opi.Name;
        }
        private bool Accepts(Port port)
        {
            if (port == null)
            {
                return false;
            }
            if (list.IsConnected)
            {
                return false;
            }
            if (port.DataType != null && port.IsList)
            {
                list.DataType = port.DataType;
                GetProperties();
                return true;
            }
            return false;
        }
        private void GetProperties()
        {
            pr.Items.Clear();
            foreach (var item in GetPropertyMenuItems(GraphCore.GetListSubType(list.DataType), true))
            {
                pr.Items.Add(item);
            }
        }
        public override void OnLoad()
        {
            GetProperties();
        }
        public override void UpdateResults()
        {
            get.Instructions = GetValue(list) + ".ConvertAll<" +="" graphcore.getlistsubtype(get.datatype).fullname="" +="" "="">(x => x." + list.Value + ")";
        }
    }
}

</"></object>