public IEnumerable <Node> TransformNode(Node node) { if (!initialized) { initialized = true; yield return(new Node { Type = NodeType.DocumentStart }); yield return(new Node { Type = NodeType.CollectionStart }); } var transformedNodes = tableTransform.TransformNode(node); var rows = from n in transformedNodes where n.RawType == NodeType.Object || n.RawType == NodeType.Property || n.RawType == NodeType.Value select n; foreach (var row in rows) { yield return(row); } }
public IEnumerable <Node> TransformNode(Node node) { var emittedNodes = tableTransform.TransformNode(node); foreach (var emittedNode in emittedNodes) { switch (emittedNode.Type) { case NodeType.ObjectStart: { yield return(new Node { Type = NodeType.CollectionStart, Value = emittedNode.Value }); break; } case NodeType.ObjectEnd: { yield return(new Node { Type = NodeType.CollectionEnd, Value = emittedNode.Value }); break; } case NodeType.PropertyStart: case NodeType.PropertyEnd: { // omitindo... break; } default: { yield return(emittedNode); break; } } } }
public IEnumerable <Node> TransformNode(Node node) { var emittedNodes = tableTransform.TransformNode(node); foreach (var emittedNode in emittedNodes) { switch (emittedNode.Type) { case NodeType.ObjectStart: { fields.Clear(); yield return(emittedNode); break; } case NodeType.ObjectEnd: { if (fieldNames == null) { fieldNames = fields.Keys.Where(fieldFilter).ToArray(); } foreach (var fieldName in fieldNames) { var field = ( from item in fields where item.Key.Equals(fieldName, StringComparison.InvariantCultureIgnoreCase) select item.Value ).FirstOrDefault(); if (field != null) { foreach (var queuedNode in field) { yield return(queuedNode); } } else { yield return(new Node { Type = NodeType.PropertyStart, Value = fieldName }); yield return(new Node { Type = NodeType.Value, Value = null }); yield return(new Node { Type = NodeType.PropertyEnd }); } } yield return(emittedNode); break; } case NodeType.PropertyStart: { currentField = new Queue <Node>(); currentField.Enqueue(emittedNode); var fieldName = (string)emittedNode.Value; fields[fieldName] = currentField; break; } case NodeType.PropertyEnd: case NodeType.Value: { currentField.Enqueue(emittedNode); break; } default: { yield return(emittedNode); break; } } } }