String Sort Lines


Node Information
Sorts the lines in the given text in alphabetical order, the result will be fed to 'Result' port, you also have the option to remove the empty lines.
General Information
• This node doesn't have other available options.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Text IN String ONE FALSE FALSE
RemoveEmptyLines IN Boolean ONE FALSE FALSE
Result OUT String MULTIPLE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.String
{
    [IsNode("Sort Lines")]
    public class StringSortLines : Node
    {
        Port a = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "Text");
        Port re = new Port(PortType.IN, typeof(bool), AcceptsLinks.ONE, "RemoveEmptyLines");
        Port res = new Port(PortType.OUT, typeof(string), AcceptsLinks.MULTIPLE, "Result");
        public bool RemoveEmptyLines
        {
            set { re.Value = value.ToString(); }
            get { return GetRuntimeValue(re); }
        }
        public string Text
        {
            set { a.Value = value; }
            get { return GetRuntimeValue(a); }
        }
        public StringSortLines()
        {
            NodeType = NodeType.Function;
            ReturnType = typeof(string);
            Name = "String Sort Lines";
            AddPort(a);
            AddPort(re);
            AddPort(res);
            Information = "Sorts the lines in the given text in alphabetical order, the result will be fed to 'Result' port, you also have the option to remove the empty lines.";
        }
        public override string Code()
        {
            string code = string.Empty;
            string removeempty = string.Empty;
            if (RemoveEmptyLines)
            {
                removeempty = ", StringSplitOptions.RemoveEmptyEntries";
            }
            return "StringBuilder n = new StringBuilder(); foreach (var item in " + GetValue(a) + ".Split(new[] { '" + @"\r" + "', '" + @"\n" + "' }" + removeempty + ").OrderBy(a => a)) { n.AppendLine(item); } return n.ToString();";
        }
    }
}