static Dictionary <string, object> SerializeSchema(SchemaNode node, ISet <SchemaNode> parentNodes, string type = null) { var ret = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(node.Name)) { ret.Add("name", node.Name); } ret.Add("type", Enum.GetName(typeof(NodeType), node.NodeType)); if (string.IsNullOrEmpty(type)) { ret.Add("schemaTypes", node.SchemaTypes.ToList()); } ret.Add("contentTypes", node.ContentTypes.Select(t => Enum.GetName(typeof(ContentType), t)).ToList()); var retValue = new Dictionary <string, object>(); if (node.ValueCount.Total > 0) { retValue.Add("totalCount", node.ValueCount.Total); } if (node.ValueCount.Empty > 0) { retValue.Add("emptyCount", node.ValueCount.Empty); } if (node.ValueLength.Min.HasValue) { retValue.Add("length", new Dictionary <string, object> { { "min", node.ValueLength.Min }, { "max", node.ValueLength.Max } }); } if (node.NumericValues.Min.HasValue) { retValue.Add("numeric", new Dictionary <string, object> { { "min", node.NumericValues.Min }, { "max", node.NumericValues.Max } }); } if (node.DateTimeValues.Min.HasValue) { retValue.Add("dateTime", new Dictionary <string, object> { { "min", node.DateTimeValues.Min }, { "max", node.DateTimeValues.Max } }); } if (node.TimeSpanValues.Min.HasValue) { retValue.Add("timeSpan", new Dictionary <string, object> { { "min", node.TimeSpanValues.Min }, { "max", node.TimeSpanValues.Max } }); } if (retValue.Any()) { ret.Add("value", retValue); } if (!parentNodes.Add(node)) { ret.Add("isCircular", true); } else { ret.Add("children", node.ChildNodes .Where(n => string.IsNullOrEmpty(type) || n.SchemaTypes.Contains(type)) .Select(n => SerializeSchema(n, new HashSet <SchemaNode>(parentNodes), type)).ToList()); } return(ret); }
internal void AddNode(SchemaNode node) => _allNodes.Add(node);