String Sort Lines


Node Information
Sorts the lines in the given text in alphabetical order, the result will be directly written back to the source, 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
Sort IN RUN MULTIPLE FALSE FALSE
Text IN String ONE FALSE FALSE
RemoveEmptyLines IN Boolean ONE FALSE FALSE

Source
namespace Korduene.KGraph.Nodes.String
{
    [IsNode("Sort Lines (Direct)")]
    public class StringSortLinesDirect : Node
    {
        Port run = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Sort");
        Port a = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "Text");
        Port re = new Port(PortType.IN, typeof(bool), AcceptsLinks.ONE, "RemoveEmptyLines");
        public bool RemoveEmptyLines
        {
            set { re.Value = value.ToString(); }
            get { return GetRuntimeValue(re); }
        }
        public StringSortLinesDirect()
        {
            NodeType = NodeType.Method;
            Name = "String Sort Lines";
            AddPort(run);
            AddPort(a);
            AddPort(re);
            Information = "Sorts the lines in the given text in alphabetical order, the result will be directly written back to the source, 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); } " + GetValue(a) + "= n.ToString();";
        }
    }
}