1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Xml;
- namespace NTERA.Engine.Compiler
- {
- [DebuggerDisplay("{Type}")]
- public class ExecutionNode : IEnumerable<ExecutionNode>
- {
- public string Type { get; set; }
- public Dictionary<string, string> Metadata { get; set; } = new Dictionary<string, string>();
- public string Anchor { get; set; }
- public Marker Symbol { get; set; }
- public ExecutionNode[] SubNodes { get; set; } = new ExecutionNode[0];
- public string this[string type]
- {
- get => Metadata[type];
- set => Metadata[type] = value;
- }
- public ExecutionNode this[int index]
- {
- get => SubNodes[index];
- set => SubNodes[index] = value;
- }
- public ExecutionNode GetSubtype(string subType)
- {
- return SubNodes.Single(x => x.Type == subType);
- }
- public void WriteXml(XmlWriter writer)
- {
- writer.WriteStartElement(Type);
- foreach (var kv in Metadata)
- writer.WriteAttributeString(kv.Key, kv.Value);
- foreach (var node in SubNodes)
- node.WriteXml(writer);
- writer.WriteEndElement();
- }
- public IEnumerator<ExecutionNode> GetEnumerator()
- {
- return ((IEnumerable<ExecutionNode>)SubNodes).GetEnumerator();
- }
- IEnumerator IEnumerable.GetEnumerator()
- {
- return SubNodes.GetEnumerator();
- }
- }
- }
|