Join Strings


Node Information
Joins the given strings into one string as the result. Click the info button to add more strings. Click the Info Button to add a new string Port.
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
A IN String ONE FALSE FALSE
B IN String ONE FALSE FALSE
Result OUT String MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.String
{
    [IsNode("Join")]
    public class StringJoin : Node
    {
        Port a = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "A");
        Port b = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "B");
        Port res = new Port(PortType.OUT, typeof(string), AcceptsLinks.MULTIPLE, "Result");
        [System.ComponentModel.Browsable(true)]
        [IsNode("This will insert the specified string or character between the two strings")]
        public string Middle
        {
            set { Settings[0] = value; }
            get { return Settings[0]; }
        }
        [System.ComponentModel.Browsable(true)]
        [IsNode("If true, it will create spaces between the strings")]
        public bool Space
        {
            set { Settings[1] = value.ToString(); }
            get { return bool.Parse(Settings[1]); }
        }
        public StringJoin()
        {
            this.NodeType = KGraph.NodeType.Function;
            this.ReturnType = typeof(string);
            OptionsAvilable = true;
            this.Name = "Join Strings";
            Space = false;
            AddPort(a);
            AddPort(b);
            AddPort(res);
            Information = "Joins the given strings into one string as the result. Click the info button to add more strings. Click the Info Button to add a new string Port.";
            IsInfoMenuEnabled = true;
            InfoButton.Click += infoButton_Click;
        }
        void infoButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (IsInfoMenuEnabled)
            {
                string porttext = GetABC(PortInCount());
                Port p = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, porttext, true);
                p.IsRemovable = true;
                AddPort(p);
            }
        }
        public override string Code()
        {
            string code = string.Empty;
            string mid = string.Empty;
            string sp = string.Empty;
            string join = string.Empty;
            if (!string.IsNullOrWhiteSpace(Settings[0]))
            {
                mid = Settings[0];
            }
            if (Space)
            {
                sp = q + " " + q;
            }
            foreach (var port in Ports)
            {
                if (port.PortType == PortType.IN)
                {
                    join += GetValue(port);
                    if (Space)
                    {
                        join += "+" + sp;
                    }
                    else
                    {
                        join += "+";
                    }
                    if (!string.IsNullOrWhiteSpace(mid))
                    {
                        join += "+ @" + q + mid + q + " +";
                        if (Space)
                        {
                            join += sp + " +";
                        }
                    }
                    else
                    {
                        join += "+";
                    }
                }
            }
            join = join.Replace("++", "+");
            join = join.Remove(join.Length - 1, 1);
            code = "return " + join + ";";
            return code;
        }
    }
}