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


C# JsonWriter.WriteComment方法代码示例

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


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

示例1: SerializeNode

    private void SerializeNode(JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
    {
      switch (node.NodeType)
      {
        case XmlNodeType.Document:
        case XmlNodeType.DocumentFragment:
          SerializeGroupedNodes(writer, node, manager, writePropertyName);
          break;
        case XmlNodeType.Element:
          if (IsArray(node) && node.ChildNodes.All(n => n.LocalName == node.LocalName) && node.ChildNodes.Count > 0)
          {
            SerializeGroupedNodes(writer, node, manager, false);
          }
          else
          {
            foreach (IXmlNode attribute in node.Attributes)
            {
              if (attribute.NamespaceUri == "http://www.w3.org/2000/xmlns/")
              {
                string prefix = (attribute.LocalName != "xmlns")
                                  ? attribute.LocalName
                                  : string.Empty;

                manager.AddNamespace(prefix, attribute.Value);
              }
            }

            if (writePropertyName)
              writer.WritePropertyName(GetPropertyName(node, manager));

            if (!ValueAttributes(node.Attributes).Any() && node.ChildNodes.Count == 1
                && node.ChildNodes[0].NodeType == XmlNodeType.Text)
            {
              // write elements with a single text child as a name value pair
              writer.WriteValue(node.ChildNodes[0].Value);
            }
            else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty(node.Attributes))
            {
              // empty element
              writer.WriteNull();
            }
            else
            {
              writer.WriteStartObject();

              for (int i = 0; i < node.Attributes.Count; i++)
              {
                SerializeNode(writer, node.Attributes[i], manager, true);
              }

              SerializeGroupedNodes(writer, node, manager, true);

              writer.WriteEndObject();
            }
          }

          break;
        case XmlNodeType.Comment:
          if (writePropertyName)
            writer.WriteComment(node.Value);
          break;
        case XmlNodeType.Attribute:
        case XmlNodeType.Text:
        case XmlNodeType.CDATA:
        case XmlNodeType.ProcessingInstruction:
        case XmlNodeType.Whitespace:
        case XmlNodeType.SignificantWhitespace:
          if (node.NamespaceUri == "http://www.w3.org/2000/xmlns/" && node.Value == JsonNamespaceUri)
            return;

          if (node.NamespaceUri == JsonNamespaceUri)
          {
            if (node.LocalName == "Array")
              return;
          }

          if (writePropertyName)
            writer.WritePropertyName(GetPropertyName(node, manager));
          writer.WriteValue(node.Value);
          break;
        case XmlNodeType.XmlDeclaration:
          IXmlDeclaration declaration = (IXmlDeclaration)node;
          writer.WritePropertyName(GetPropertyName(node, manager));
          writer.WriteStartObject();

          if (!string.IsNullOrEmpty(declaration.Version))
          {
            writer.WritePropertyName("@version");
            writer.WriteValue(declaration.Version);
          }
          if (!string.IsNullOrEmpty(declaration.Encoding))
          {
            writer.WritePropertyName("@encoding");
            writer.WriteValue(declaration.Encoding);
          }
          if (!string.IsNullOrEmpty(declaration.Standalone))
          {
            writer.WritePropertyName("@standalone");
            writer.WriteValue(declaration.Standalone);
          }
//.........这里部分代码省略.........
开发者ID:284247028,项目名称:MvvmCross,代码行数:101,代码来源:XmlNodeConverter.cs

示例2: WriteTo

 /// <summary>
 /// Writes this token to a <see cref="JsonWriter"/>.
 /// </summary>
 /// <param name="writer">A <see cref="JsonWriter"/> into which this method will write.</param>
 /// <param name="converters">A collection of <see cref="JsonConverter"/> which will be used when writing the token.</param>
 public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
 {
     switch (_valueType)
       {
     case JsonTokenType.Comment:
       writer.WriteComment(_value.ToString());
       break;
     case JsonTokenType.Integer:
       WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToInt64(v, CultureInfo.InvariantCulture)), _value);
       break;
     case JsonTokenType.Float:
       WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToDouble(v, CultureInfo.InvariantCulture)), _value);
       break;
     case JsonTokenType.String:
       WriteConvertableValue(writer, converters, v => writer.WriteValue(v.ToString()), _value);
       break;
     case JsonTokenType.Boolean:
       WriteConvertableValue(writer, converters, v => writer.WriteValue(Convert.ToBoolean(v, CultureInfo.InvariantCulture)), _value);
       break;
     case JsonTokenType.Date:
       WriteConvertableValue(writer, converters, v =>
       {
     if (v is DateTimeOffset)
       writer.WriteValue((DateTimeOffset)v);
     else
       writer.WriteValue(Convert.ToDateTime(v, CultureInfo.InvariantCulture));
       }, _value);
       break;
     case JsonTokenType.Raw:
       writer.WriteRawValue(_value.ToString());
       break;
     case JsonTokenType.Null:
       writer.WriteNull();
       break;
     case JsonTokenType.Undefined:
       writer.WriteUndefined();
       break;
     default:
       throw MiscellaneousUtils.CreateArgumentOutOfRangeException("TokenType", _valueType, "Unexpected token type.");
       }
 }
开发者ID:jabbo,项目名称:Jabbo,代码行数:46,代码来源:JValue.cs

示例3: SerializeNode

    private void SerializeNode(JsonWriter writer, XmlNode node, bool writePropertyName)
    {
      switch (node.NodeType)
      {
        case XmlNodeType.Document:
        case XmlNodeType.DocumentFragment:
          SerializeGroupedNodes(writer, node);
          break;
        case XmlNodeType.Element:
          if (writePropertyName)
            writer.WritePropertyName(node.Name);

          if (ValueAttributes(node.Attributes).Count() == 0 && node.ChildNodes.Count == 1
                  && node.ChildNodes[0].NodeType == XmlNodeType.Text)
          {
            // write elements with a single text child as a name value pair
            writer.WriteValue(node.ChildNodes[0].Value);
          }
          else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty(node.Attributes))
          {
            // empty element
            writer.WriteNull();
          }
          else if (node.ChildNodes.OfType<XmlElement>().Where(x => x.Name.StartsWith("-")).Count() > 1)
          {
            XmlElement constructorValueElement = node.ChildNodes.OfType<XmlElement>().Where(x => x.Name.StartsWith("-")).First();
            string constructorName = constructorValueElement.Name.Substring(1);

            writer.WriteStartConstructor(constructorName);

            for (int i = 0; i < node.ChildNodes.Count; i++)
            {
              SerializeNode(writer, node.ChildNodes[i], false);
            }

            writer.WriteEndConstructor();
          }
          else
          {
            writer.WriteStartObject();

            for (int i = 0; i < node.Attributes.Count; i++)
            {
              SerializeNode(writer, node.Attributes[i], true);
            }

            SerializeGroupedNodes(writer, node);

            writer.WriteEndObject();
          }

          break;
        case XmlNodeType.Comment:
          if (writePropertyName)
            writer.WriteComment(node.Value);
          break;
        case XmlNodeType.Attribute:
        case XmlNodeType.Text:
        case XmlNodeType.CDATA:
        case XmlNodeType.ProcessingInstruction:
        case XmlNodeType.Whitespace:
        case XmlNodeType.SignificantWhitespace:
          if (node.Prefix == "xmlns" && node.Value == JsonNamespaceUri)
            break;
          else if (node.NamespaceURI == JsonNamespaceUri)
            break;

          if (writePropertyName)
            writer.WritePropertyName(GetPropertyName(node));
          writer.WriteValue(node.Value);
          break;
        case XmlNodeType.XmlDeclaration:
          XmlDeclaration declaration = (XmlDeclaration)node;
          writer.WritePropertyName(GetPropertyName(node));
          writer.WriteStartObject();

          if (!string.IsNullOrEmpty(declaration.Version))
          {
            writer.WritePropertyName("@version");
            writer.WriteValue(declaration.Version);
          }
          if (!string.IsNullOrEmpty(declaration.Encoding))
          {
            writer.WritePropertyName("@encoding");
            writer.WriteValue(declaration.Encoding);
          }
          if (!string.IsNullOrEmpty(declaration.Standalone))
          {
            writer.WritePropertyName("@standalone");
            writer.WriteValue(declaration.Standalone);
          }

          writer.WriteEndObject();
          break;
        default:
          throw new JsonSerializationException("Unexpected XmlNodeType when serializing nodes: " + node.NodeType);
      }
    }
开发者ID:matthewcanty,项目名称:worldpay-lib-dotnet,代码行数:98,代码来源:XmlNodeConverter.cs

示例4: Indenting

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

      using (JsonWriter jsonWriter = new JsonWriter(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();
      }

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

      Console.WriteLine("Indenting");
      Console.WriteLine(result);

      Assert.AreEqual(expected, result);
    }
开发者ID:webgrid,项目名称:WebGrid,代码行数:41,代码来源:JsonWriterTest.cs

示例5: WriteTo

 public override void WriteTo(JsonWriter writer)
 {
     switch (_valueType)
       {
     case JsonTokenType.Comment:
       writer.WriteComment(_value.ToString());
       break;
     case JsonTokenType.Integer:
       writer.WriteValue(Convert.ToInt64(_value));
       break;
     case JsonTokenType.Float:
       writer.WriteValue(Convert.ToDouble(_value));
       break;
     case JsonTokenType.String:
       writer.WriteValue(_value.ToString());
       break;
     case JsonTokenType.Boolean:
       writer.WriteValue(Convert.ToBoolean(_value));
       break;
     case JsonTokenType.Null:
       writer.WriteNull();
       break;
     case JsonTokenType.Undefined:
       writer.WriteUndefined();
       break;
     case JsonTokenType.Date:
       writer.WriteValue(Convert.ToDateTime(_value));
       break;
     default:
       throw new ArgumentOutOfRangeException("TokenType", _valueType, "Unexpected token type.");
       }
 }
开发者ID:nhatkycon,项目名称:AoCuoiHongNhung,代码行数:32,代码来源:JValue.cs

示例6: SerializeNode

 // Token: 0x060006E1 RID: 1761
 // RVA: 0x00037C10 File Offset: 0x00035E10
 private void SerializeNode(JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
 {
     switch (node.NodeType)
     {
     case XmlNodeType.Element:
         if (this.IsArray(node))
         {
             if (Enumerable.All<IXmlNode>(node.ChildNodes, (IXmlNode n) => n.LocalName == node.LocalName) && node.ChildNodes.Count > 0)
             {
                 this.SerializeGroupedNodes(writer, node, manager, false);
                 return;
             }
         }
         manager.PushScope();
         foreach (IXmlNode current in node.Attributes)
         {
             if (current.NamespaceUri == "http://www.w3.org/2000/xmlns/")
             {
                 string prefix = (current.LocalName != "xmlns") ? current.LocalName : string.Empty;
                 string value = current.Value;
                 manager.AddNamespace(prefix, value);
             }
         }
         if (writePropertyName)
         {
             writer.WritePropertyName(this.GetPropertyName(node, manager));
         }
         if (!Enumerable.Any<IXmlNode>(this.ValueAttributes(node.Attributes)) && node.ChildNodes.Count == 1 && node.ChildNodes[0].NodeType == XmlNodeType.Text)
         {
             writer.WriteValue(node.ChildNodes[0].Value);
         }
         else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty<IXmlNode>(node.Attributes))
         {
             IXmlElement xmlElement = (IXmlElement)node;
             if (xmlElement.IsEmpty)
             {
                 writer.WriteNull();
             }
             else
             {
                 writer.WriteValue(string.Empty);
             }
         }
         else
         {
             writer.WriteStartObject();
             for (int i = 0; i < node.Attributes.Count; i++)
             {
                 this.SerializeNode(writer, node.Attributes[i], manager, true);
             }
             this.SerializeGroupedNodes(writer, node, manager, true);
             writer.WriteEndObject();
         }
         manager.PopScope();
         return;
     case XmlNodeType.Attribute:
     case XmlNodeType.Text:
     case XmlNodeType.CDATA:
     case XmlNodeType.ProcessingInstruction:
     case XmlNodeType.Whitespace:
     case XmlNodeType.SignificantWhitespace:
         if (node.NamespaceUri == "http://www.w3.org/2000/xmlns/" && node.Value == "http://james.newtonking.com/projects/json")
         {
             return;
         }
         if (node.NamespaceUri == "http://james.newtonking.com/projects/json" && node.LocalName == "Array")
         {
             return;
         }
         if (writePropertyName)
         {
             writer.WritePropertyName(this.GetPropertyName(node, manager));
         }
         writer.WriteValue(node.Value);
         return;
     case XmlNodeType.Comment:
         if (writePropertyName)
         {
             writer.WriteComment(node.Value);
             return;
         }
         return;
     case XmlNodeType.Document:
     case XmlNodeType.DocumentFragment:
         this.SerializeGroupedNodes(writer, node, manager, writePropertyName);
         return;
     case XmlNodeType.DocumentType:
     {
         IXmlDocumentType xmlDocumentType = (IXmlDocumentType)node;
         writer.WritePropertyName(this.GetPropertyName(node, manager));
         writer.WriteStartObject();
         if (!string.IsNullOrEmpty(xmlDocumentType.Name))
         {
             writer.WritePropertyName("@name");
             writer.WriteValue(xmlDocumentType.Name);
         }
         if (!string.IsNullOrEmpty(xmlDocumentType.Public))
         {
//.........这里部分代码省略.........
开发者ID:newchild,项目名称:Project-DayZero,代码行数:101,代码来源:XmlNodeConverter.cs

示例7: SerializeNode

        private void SerializeNode(JsonWriter writer, IXmlNode node, XmlNamespaceManager manager, bool writePropertyName)
        {
            switch (node.NodeType)
            {
                case XmlNodeType.Document:
                case XmlNodeType.DocumentFragment:
                    SerializeGroupedNodes(writer, node, manager, writePropertyName);
                    break;
                case XmlNodeType.Element:
                    if (IsArray(node) && node.ChildNodes.All(n => n.LocalName == node.LocalName) && node.ChildNodes.Count > 0)
                        SerializeGroupedNodes(writer, node, manager, false);
                    else
                    {
                        manager.PushScope();

                        foreach (var attribute in node.Attributes)
                        {
                            if (attribute.NamespaceUri != "http://www.w3.org/2000/xmlns/") continue;
                            var namespacePrefix = (attribute.LocalName != "xmlns") ? attribute.LocalName : string.Empty;
                            var namespaceUri = attribute.Value;
                            manager.AddNamespace(namespacePrefix, namespaceUri);
                        }

                        if (writePropertyName)
                            writer.WritePropertyName(GetPropertyName(node, manager));

                        if (!ValueAttributes(node.Attributes).Any() && node.ChildNodes.Count == 1 && node.ChildNodes[0].NodeType == XmlNodeType.Text)
                            // write elements with a single text child as a name value pair
                            writer.WriteValue(node.ChildNodes[0].Value);
                        else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty(node.Attributes))
                        {
                            var element = (IXmlElement) node;

                            // empty element
                            if (element.IsEmpty)
                                writer.WriteNull();
                            else
                                writer.WriteValue(string.Empty);
                        }
                        else
                        {
                            writer.WriteStartObject();

                            for (var i = 0; i < node.Attributes.Count; i++)
                                SerializeNode(writer, node.Attributes[i], manager, true);

                            SerializeGroupedNodes(writer, node, manager, true);

                            writer.WriteEndObject();
                        }

                        manager.PopScope();
                    }

                    break;
                case XmlNodeType.Comment:
                    if (writePropertyName)
                        writer.WriteComment(node.Value);
                    break;
                case XmlNodeType.Attribute:
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    if (node.NamespaceUri == "http://www.w3.org/2000/xmlns/" && node.Value == JsonNamespaceUri)
                        return;

                    if (node.NamespaceUri == JsonNamespaceUri)
                        if (node.LocalName == "Array")
                            return;

                    if (writePropertyName)
                        writer.WritePropertyName(GetPropertyName(node, manager));
                    writer.WriteValue(node.Value);
                    break;
                case XmlNodeType.XmlDeclaration:
                    var declaration = (IXmlDeclaration) node;
                    writer.WritePropertyName(GetPropertyName(node, manager));
                    writer.WriteStartObject();

                    if (!string.IsNullOrEmpty(declaration.Version))
                    {
                        writer.WritePropertyName("@version");
                        writer.WriteValue(declaration.Version);
                    }
                    if (!string.IsNullOrEmpty(declaration.Encoding))
                    {
                        writer.WritePropertyName("@encoding");
                        writer.WriteValue(declaration.Encoding);
                    }
                    if (!string.IsNullOrEmpty(declaration.Standalone))
                    {
                        writer.WritePropertyName("@standalone");
                        writer.WriteValue(declaration.Standalone);
                    }

                    writer.WriteEndObject();
                    break;
                case XmlNodeType.DocumentType:
//.........这里部分代码省略.........
开发者ID:sat1582,项目名称:CODEFramework,代码行数:101,代码来源:XmlNodeConverter.cs

示例8: SerializeNode

        private void SerializeNode(JsonWriter writer, XmlNode node, bool writePropertyName)
        {
            switch (node.NodeType)
            {
                case XmlNodeType.Document:
                case XmlNodeType.DocumentFragment:
                    SerializeGroupedNodes(writer, node);
                    break;
                case XmlNodeType.Element:
                    if (writePropertyName)
                        writer.WritePropertyName(node.Name);

                    if (CollectionUtils.IsNullOrEmpty(node.Attributes) && node.ChildNodes.Count == 1
                        && node.ChildNodes[0].NodeType == XmlNodeType.Text)
                    {
                        // write elements with a single text child as a name value pair
                        writer.WriteValue(node.ChildNodes[0].Value);
                    }
                    else if (node.ChildNodes.Count == 0 && CollectionUtils.IsNullOrEmpty(node.Attributes))
                    {
                        // empty element
                        writer.WriteNull();
                    }
                    else
                    {
                        writer.WriteStartObject();

                        for (int i = 0; i < node.Attributes.Count; i++)
                        {
                            SerializeNode(writer, node.Attributes[i], true);
                        }

                        SerializeGroupedNodes(writer, node);

                        writer.WriteEndObject();
                    }

                    break;
                case XmlNodeType.Comment:
                    if (writePropertyName)
                        writer.WriteComment(node.Value);
                    break;
                case XmlNodeType.Attribute:
                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.ProcessingInstruction:
                case XmlNodeType.Whitespace:
                case XmlNodeType.SignificantWhitespace:
                    if (writePropertyName)
                        writer.WritePropertyName(GetPropertyName(node));
                    writer.WriteValue(node.Value);
                    break;
                case XmlNodeType.XmlDeclaration:
                    XmlDeclaration declaration = (XmlDeclaration)node;
                    writer.WritePropertyName(GetPropertyName(node));
                    writer.WriteStartObject();

                    if (!string.IsNullOrEmpty(declaration.Version))
                    {
                        writer.WritePropertyName("@version");
                        writer.WriteValue(declaration.Version);
                    }
                    if (!string.IsNullOrEmpty(declaration.Encoding))
                    {
                        writer.WritePropertyName("@encoding");
                        writer.WriteValue(declaration.Encoding);
                    }
                    if (!string.IsNullOrEmpty(declaration.Standalone))
                    {
                        writer.WritePropertyName("@standalone");
                        writer.WriteValue(declaration.Standalone);
                    }

                    writer.WriteEndObject();
                    break;
                default:
                    throw new Exception("Unexpected XmlNodeType when serializing nodes: " + node.NodeType);
            }
        }
开发者ID:mrkurt,项目名称:mubble-old,代码行数:79,代码来源:XmlNodeConverter.cs


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