public void WriteTo(string jsonFilepath) { current = input; using (var writer = new JsonWriter(jsonFilepath)) { ParseDocument(writer); } }
private void ClumpJsonFromDirectoryIntoFile(string sourceDirectoryPath) { var clumpedFilepath = Path.Combine(configuration.OutputDirectory, "xaml.json"); using (var clumpedWriter = new JsonWriter(clumpedFilepath)) { clumpedWriter.StartBlock(); foreach (var jsonFile in Directory.GetFiles(sourceDirectoryPath, "*.json")) { var propertyName = Path.GetFileName(jsonFile); clumpedWriter.WriteRawProperty(propertyName, File.ReadAllText(jsonFile)); } clumpedWriter.EndBlock(); } }
private void ParseContent(JsonWriter writer) { while (Next()) { switch (current.NodeType) { case XmlNodeType.Element: ParseElement(writer); continue; case XmlNodeType.EndElement: continue; default: Console.WriteLine(current.NodeType); break; } } }
private void ParseDocument(JsonWriter writer) { ParseContent(writer); }
private void ParseElementChildren(JsonWriter writer) { if (current.IsEmptyElement) return; writer.StartArray("$Elements"); Descend(); Next(); ParseContent(writer); Ascend(); Next(); writer.EndArray(); }
private void ParseElementAttributes(JsonWriter writer) { if (!current.HasAttributes) return; current.MoveToFirstAttribute(); do { string attributeName = GetCurrentAttributeName(); string attributeValue = current.Value; writer.WriteProperty(attributeName, attributeValue); } while (current.MoveToNextAttribute()); current.MoveToElement(); }
private void ParseElement(JsonWriter writer) { writer.StartBlock(); writer.WriteProperty("$ElementType", current.LocalName); ParseElementAttributes(writer); ParseElementChildren(writer); writer.EndBlock(); }