private static string Convert(string path) { var schemaText = File.ReadAllText(path); var jset = new JsonLoadSettings { CommentHandling = CommentHandling.Load }; var obj = JToken.Parse(schemaText, jset); return(JTokenConverter.Convert(obj)); }
private async void JsonMenuItemCallback(object sender, EventArgs e) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); try { var schemaText = Clipboard.GetText(); var doc = JToken.Parse(schemaText, new JsonLoadSettings { CommentHandling = CommentHandling.Load }); var classText = JTokenConverter.Convert(doc, Options.ToConverterOptions()); try { dte.UndoContext.Open("Paste JSON Schema as Class"); var selection = (TextSelection)dte.ActiveDocument.Selection; if (selection != null) { selection.Insert(classText); dte.ActiveDocument.Activate(); dte.ExecuteCommand("Edit.FormatDocument"); } } finally { dte.UndoContext.Close(); } } catch (Exception ex) { MessageBox.Show( "Copied text is not a JSON!\r\n" + ex.Message, "JSON Error", MessageBoxButton.OK, MessageBoxImage.Error); } }