Files
PepApi.Core/PepLib.Core/Node.cs
AJ 7c5b4ded5f chore(PepLib.Core): remove unused using directives and clean up formatting
Remove unnecessary System, System.Collections.Generic, System.IO, and
System.Linq using directives that were flagged by IDE analyzers. Also
includes minor whitespace and code style normalization.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 07:52:17 -05:00

83 lines
1.7 KiB
C#

namespace PepLib
{
public class Node
{
private Node parent;
public List<Node> Children;
public Node()
{
Children = new List<Node>();
}
public Node Parent
{
get { return parent; }
set
{
parent = value;
UpdateDepth();
}
}
public string Value { get; set; }
private void UpdateDepth()
{
if (Parent != null)
Level = Parent.Level + 1;
else
Level = 0;
foreach (var node in Children)
node.Parent = this;
}
public int Level { get; protected set; }
public void AddChild(Node node)
{
node.Parent = this;
Children.Add(node);
}
public void Write(TextWriter writer)
{
writer.WriteLine("".PadLeft(Level * 2) + this.ToString());
foreach (var node in Children)
node.Write(writer);
}
public override string ToString()
{
return Value;
}
}
public class KeyNode : Node
{
public string Name;
public static KeyNode Parse(Node node)
{
var index = node.Value.IndexOf('=');
if (index == -1)
return null;
return new KeyNode()
{
Name = node.Value.Remove(index),
Value = node.Value.Remove(0, index + 1).Trim()
};
}
public override string ToString()
{
return string.Format("{0}={1}", Name, Value);
}
}
}