ExecutionNode.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Xml;
  6. namespace NTERA.Engine.Compiler
  7. {
  8. [DebuggerDisplay("{Type}")]
  9. public class ExecutionNode : IEnumerable<ExecutionNode>
  10. {
  11. public string Type { get; set; }
  12. public Dictionary<string, string> Metadata { get; set; } = new Dictionary<string, string>();
  13. public string Anchor { get; set; }
  14. public Marker Symbol { get; set; }
  15. public ExecutionNode[] SubNodes { get; set; } = new ExecutionNode[0];
  16. public ExecutionNode this[string type]
  17. {
  18. get { return SubNodes.First(x => x.Type == type); }
  19. }
  20. public ExecutionNode this[int index]
  21. {
  22. get => SubNodes[index];
  23. set => SubNodes[index] = value;
  24. }
  25. public void WriteXml(XmlWriter writer)
  26. {
  27. writer.WriteStartElement(Type);
  28. foreach (var kv in Metadata)
  29. writer.WriteAttributeString(kv.Key, kv.Value);
  30. foreach (var node in SubNodes)
  31. node.WriteXml(writer);
  32. writer.WriteEndElement();
  33. }
  34. public IEnumerator<ExecutionNode> GetEnumerator()
  35. {
  36. return ((IEnumerable<ExecutionNode>)SubNodes).GetEnumerator();
  37. }
  38. IEnumerator IEnumerable.GetEnumerator()
  39. {
  40. return SubNodes.GetEnumerator();
  41. }
  42. }
  43. }