当前位置: 首页>>代码示例>>C#>>正文


C# JsonTextWriter.WriteComment方法代码示例

本文整理汇总了C#中Newtonsoft.Json.JsonTextWriter.WriteComment方法的典型用法代码示例。如果您正苦于以下问题:C# JsonTextWriter.WriteComment方法的具体用法?C# JsonTextWriter.WriteComment怎么用?C# JsonTextWriter.WriteComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.JsonTextWriter的用法示例。


在下文中一共展示了JsonTextWriter.WriteComment方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 static void Main(string[] args)
 {
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     using (JsonWriter writer = new JsonTextWriter(sw))
     {
         writer.Formatting = Newtonsoft.Json.Formatting.Indented;
         writer.WriteStartObject();
         writer.WritePropertyName("CPU");
         writer.WriteValue("Intel");
         writer.WritePropertyName("PSU");
         writer.WriteValue("500W");
         writer.WritePropertyName("Drives");
         writer.WriteStartArray();
         writer.WriteValue("DVD read/writer");
         writer.WriteComment("(broken)");
         writer.WriteValue("500 gigabyte hard drive");
         writer.WriteValue("200 gigabype hard drive");
         writer.WriteEnd();
         writer.WriteEndObject();
     }
     File.WriteAllText(Environment.CurrentDirectory + "/rhcdata.json", sw.ToString());
     Console.WriteLine(sw.ToString());
     Console.ReadLine();
 }
开发者ID:MaurodeLyon,项目名称:Huiswerk-CSharp,代码行数:25,代码来源:Program.cs

示例2: Indenting

    public void Indenting()
    {
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);

      using (JsonWriter jsonWriter = new JsonTextWriter(sw))
      {
        jsonWriter.Formatting = Formatting.Indented;

        jsonWriter.WriteStartObject();
        jsonWriter.WritePropertyName("CPU");
        jsonWriter.WriteValue("Intel");
        jsonWriter.WritePropertyName("PSU");
        jsonWriter.WriteValue("500W");
        jsonWriter.WritePropertyName("Drives");
        jsonWriter.WriteStartArray();
        jsonWriter.WriteValue("DVD read/writer");
        jsonWriter.WriteComment("(broken)");
        jsonWriter.WriteValue("500 gigabyte hard drive");
        jsonWriter.WriteValue("200 gigabype hard drive");
        jsonWriter.WriteEnd();
        jsonWriter.WriteEndObject();
        Assert.AreEqual(WriteState.Start, jsonWriter.WriteState);
      }

      // {
      //   "CPU": "Intel",
      //   "PSU": "500W",
      //   "Drives": [
      //     "DVD read/writer"
      //     /*(broken)*/,
      //     "500 gigabyte hard drive",
      //     "200 gigabype hard drive"
      //   ]
      // }

      string expected = @"{
  ""CPU"": ""Intel"",
  ""PSU"": ""500W"",
  ""Drives"": [
    ""DVD read/writer""
    /*(broken)*/,
    ""500 gigabyte hard drive"",
    ""200 gigabype hard drive""
  ]
}";
      string result = sb.ToString();

      Assert.AreEqual(expected, result);
    }
开发者ID:RedBanies3ofThem,项目名称:tradelink.afterlife,代码行数:50,代码来源:JsonTextWriterTest.cs

示例3: CloseWithRemainingContent

    public void CloseWithRemainingContent()
    {
      StringBuilder sb = new StringBuilder();
      StringWriter sw = new StringWriter(sb);

      using (JsonWriter jsonWriter = new JsonTextWriter(sw))
      {
        jsonWriter.Formatting = Formatting.Indented;

        jsonWriter.WriteStartObject();
        jsonWriter.WritePropertyName("CPU");
        jsonWriter.WriteValue("Intel");
        jsonWriter.WritePropertyName("PSU");
        jsonWriter.WriteValue("500W");
        jsonWriter.WritePropertyName("Drives");
        jsonWriter.WriteStartArray();
        jsonWriter.WriteValue("DVD read/writer");
        jsonWriter.WriteComment("(broken)");
        jsonWriter.WriteValue("500 gigabyte hard drive");
        jsonWriter.WriteValue("200 gigabype hard drive");
        jsonWriter.Close();
      }

      string expected = @"{
  ""CPU"": ""Intel"",
  ""PSU"": ""500W"",
  ""Drives"": [
    ""DVD read/writer""
    /*(broken)*/,
    ""500 gigabyte hard drive"",
    ""200 gigabype hard drive""
  ]
}";
      string result = sb.ToString();

      Assert.AreEqual(expected, result);
    }
开发者ID:RedBanies3ofThem,项目名称:tradelink.afterlife,代码行数:37,代码来源:JsonTextWriterTest.cs

示例4: TrStmtList

        void TrStmtList(List<Statement/*!*/>/*!*/ stmts)
        {
            Contract.Requires(cce.NonNullElements(stmts));
              List<LocalVariable> AllDecls = new List<LocalVariable>();

              using (WriteArray()) {
            j.WriteValue(KremlinAst.ESequence);
            using (WriteArray()) {
              WriteEUnit(); // in case the statement list is empty
              foreach (Statement ss in stmts) {
            // JsonTextWriter is forward-only, but after calling TrStmt() we may need
            // to go back and inject new ELet statements to introduce temp variables.
            // So call TrStmt() once to generate code to a throw-away MemoryStream,
            // but remember what temps need to be introduced.  Then introduce them
            // and call TrStmt() once more, to generate the actual Json.
            JsonTextWriter oldj = j;
            VariableTracker oldtracker = VarTracker.Clone();

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            JsonTextWriter newj = new JsonTextWriter(sw);
            newj.Formatting = oldj.Formatting;
            newj.Indentation = oldj.Indentation;
            j = newj;

            var oldVarDeclsList = varDeclsList;
            varDeclsList = new List<LocalVariable>();

            TrStmt(ss);

            j = oldj;
            VarTracker = oldtracker;
            var decls = varDeclsList; // Grab the set of just-declared variables generated by the first TrStmt() pass
            varDeclsList = null;      // Switch modes for next TrStmt() pass
            AllDecls.AddRange(decls); // Accumulate the set of all variables this stmt list has generated
            foreach (var l in decls) {
              // ELet v in { Stmt
              j.WriteStartArray();
              j.WriteValue(KremlinAst.ELet);
              j.WriteStartArray();
              WriteBinder(l, l.Name, true); // lident
              WriteDefaultValue(l.Type);    // = default
              VarTracker.Push(l);
              // "in" is the contents that follow
              j.WriteStartArray();
              j.WriteValue(KremlinAst.ESequence);
              j.WriteStartArray();
              WriteEUnit();
            }

            newj.Close();
            string RawJson = sb.ToString();
            if (RawJson != "") {
              j.WriteRaw(",");
              j.WriteWhitespace("\n");
              j.WriteRaw(RawJson); // Now paste the JSON
            }

            if (ss.Labels != null) {
              // bugbug: these appear to be used to support "Break" statements.
              j.WriteComment("Labels are unsupported: " + ss.Labels.Data.AssignUniqueId("after_", idGenerator));
            }

            varDeclsList = oldVarDeclsList;
              }

              // Now that all statements in the list have been generated, close out the nested ELets generated above
              AllDecls.Reverse();
              foreach (var l in AllDecls) {
            VarTracker.Pop(l);
            j.WriteEndArray(); // Closing out the expr list in the ESequence
            j.WriteEndArray(); // Closing out the array aboce ESequence
            j.WriteEndArray(); // Closing out the list of binder * expr * expr
            j.WriteEndArray(); // Closing out the array above ELet
              }
            }
              }
        }
开发者ID:Chris-Hawblitzel,项目名称:dafny,代码行数:78,代码来源:Kremlin.cs

示例5: ModsToJson

 private string ModsToJson(List<Mod> mods)
 {
     StringBuilder sb = new StringBuilder();
     StringWriter sw = new StringWriter(sb);
     using (JsonWriter writer = new JsonTextWriter(sw))
     {
         writer.Formatting = Formatting.Indented;
         writer.WriteComment("DO NOT EDIT THIS BY HAND WITHOUT KNOWING EXACTLY WHAT YOU ARE DOING" + Environment.NewLine + "THIS FILE IS CREATED BY MCM AND IS USED FOR KNOWING WHICH MODS ARE INSTALLED!");
         writer.WriteStartObject();
         writer.WritePropertyName("mods");
         writer.WriteStartArray();
         foreach (Mod mod in mods)
         {
             writer.WriteStartObject();
             writer.WritePropertyName("name");
             writer.WriteValue(mod.name);
             writer.WritePropertyName("path");
             writer.WriteValue(mod.path);
             writer.WritePropertyName("type");
             writer.WriteValue(mod.type);
             writer.WritePropertyName("level");
             writer.WriteValue(mod.level);
             writer.WritePropertyName("version");
             writer.WriteValue(mod.version.Key);
             writer.WriteEndObject();
         }
         writer.WriteEnd();
     }
     return sb.ToString();
 }
开发者ID:Northcode,项目名称:MCM-reboot,代码行数:30,代码来源:Main.cs

示例6: WriteJsonToTextWriter

        private static void WriteJsonToTextWriter(TextWriter textWriter, bool skipComment = false)
        {
            _serializer.Formatting = Formatting.Indented;
            if (!skipComment) WriteComment(textWriter, ConfigFormat.Json);
            using (JsonWriter writer = new JsonTextWriter(textWriter))
            {
                writer.Formatting = Formatting.Indented;
                writer.WriteStartObject();
                lock (_current)
                {
                    foreach (var kvp in _current)
                    {
                        var objType = kvp.Value.GetType();

                        var levelAttr = objType.GetCustomAttribute<ConfigKeySerializeLevelAttribute>();
                        string key;
                        if (levelAttr != null)
                        {
                            var keys = kvp.Key.Split('.');
                            key = string.Join(".", keys.Skip(keys.Length - levelAttr.Level));
                            if (string.IsNullOrEmpty(key) || levelAttr.Level == 0) continue;
                        }
                        else
                        {
                            key = kvp.Key;
                        }
                        var configAttr = objType.GetCustomAttribute<ConfigCommentAttribute>();
                        if (!string.IsNullOrEmpty(configAttr?.Comment))
                            writer.WriteComment(configAttr.Comment);
                        writer.WritePropertyName(key, false);
                        writer.WriteStartObject();
                        foreach (var prop in objType.Properties())
                        {
                            WriteJsonValue(writer, prop, prop.GetValue(kvp.Value, null), prop.PropertyType);
                        }
                        foreach (var field in objType.Fields())
                        {
                            WriteJsonValue(writer, field, field.GetValue(kvp.Value), field.FieldType);
                        }
                        writer.WriteEndObject();
                    }
                    writer.WriteEndObject();
                }
            }
        }
开发者ID:vbilopav,项目名称:CodeFirstConfig,代码行数:45,代码来源:ConfigObjects.cs

示例7: Process

            public override bool Process(HttpServer server, HttpRequest request, HttpResponse response)
            {
                if (request.Page.StartsWith("/status"))
                {
                    response.ContentType = (string)SubstitutingFileReader.MimeTypes[".html"];
                    response.ReturnCode = 200;
                    StringBuilder sb = new StringBuilder();
                    StringWriter sw = new StringWriter(sb);

                    using (JsonWriter jsonWriter = new JsonTextWriter(sw))
                    {
                        jsonWriter.Formatting = Formatting.Indented;
                        jsonWriter.WriteStartObject();
                        jsonWriter.WritePropertyName("twain_source");
                        jsonWriter.WriteValue(Properties.Settings.Default.twain_source);
                        jsonWriter.WriteComment("ID of selected TWAIN source");

                        jsonWriter.WritePropertyName("x");
                        jsonWriter.WriteValue(Properties.Settings.Default.x);
                        jsonWriter.WriteComment("The x-coordinate of the upper-left corner of the crop rectangle");

                        jsonWriter.WritePropertyName("y");
                        jsonWriter.WriteValue(Properties.Settings.Default.y);
                        jsonWriter.WriteComment("The y-coordinate of the upper-left corner of the crop rectangle");

                        jsonWriter.WritePropertyName("w");
                        jsonWriter.WriteValue(Properties.Settings.Default.w);
                        jsonWriter.WriteComment("The width of the crop rectangle");

                        jsonWriter.WritePropertyName("h");
                        jsonWriter.WriteValue(Properties.Settings.Default.h);
                        jsonWriter.WriteComment("The height of the crop rectangle");

                        jsonWriter.WritePropertyName("encode");
                        jsonWriter.WriteValue(Properties.Settings.Default.encode);
                        jsonWriter.WriteComment("Encoding setup");

                        jsonWriter.WritePropertyName("server_autostart");
                        jsonWriter.WriteValue(Properties.Settings.Default.server_autostart);
                        jsonWriter.WriteComment("Shall web server be started automatically");

                        jsonWriter.WritePropertyName("start_minimized");
                        jsonWriter.WriteValue(Properties.Settings.Default.start_minimized);
                        jsonWriter.WriteComment("Shall application start minimized");

                        jsonWriter.WritePropertyName("port");
                        jsonWriter.WriteValue(Properties.Settings.Default.port);
                        jsonWriter.WriteComment("Web server listening port");

                        jsonWriter.WritePropertyName("dpi");
                        jsonWriter.WriteValue(Properties.Settings.Default.dpi);
                        jsonWriter.WriteComment("DPI");

                        jsonWriter.WritePropertyName("colour");
                        jsonWriter.WriteValue(Properties.Settings.Default.colour == ColourSetting.Colour ? "full" : Properties.Settings.Default.colour == ColourSetting.GreyScale ? "greyscale" : "blackandwhite");
                        jsonWriter.WriteComment("Colouring setup");

                        jsonWriter.WritePropertyName("adf");
                        jsonWriter.WriteValue(Properties.Settings.Default.useADF);
                        jsonWriter.WriteComment("Shall ADF be used?");
                        jsonWriter.WriteEndObject();
                    }

                    response.Content = sb.ToString();
                    return true;
                }
                return false;
            }
开发者ID:martindobias,项目名称:ScanIt,代码行数:68,代码来源:MainForm.cs


注:本文中的Newtonsoft.Json.JsonTextWriter.WriteComment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。