ExecutionNode.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 string this[string type]
  17. {
  18. get => Metadata[type];
  19. set => Metadata[type] = value;
  20. }
  21. public ExecutionNode this[int index]
  22. {
  23. get => SubNodes[index];
  24. set => SubNodes[index] = value;
  25. }
  26. public ExecutionNode GetSubtype(string subType)
  27. {
  28. return SubNodes.Single(x => x.Type == subType);
  29. }
  30. public void WriteXml(XmlWriter writer)
  31. {
  32. writer.WriteStartElement(Type);
  33. foreach (var kv in Metadata)
  34. writer.WriteAttributeString(kv.Key, kv.Value);
  35. foreach (var node in SubNodes)
  36. node.WriteXml(writer);
  37. writer.WriteEndElement();
  38. }
  39. public IEnumerator<ExecutionNode> GetEnumerator()
  40. {
  41. return ((IEnumerable<ExecutionNode>)SubNodes).GetEnumerator();
  42. }
  43. IEnumerator IEnumerable.GetEnumerator()
  44. {
  45. return SubNodes.GetEnumerator();
  46. }
  47. }
  48. }