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


C# JsonWriter.WriteNull方法代码示例

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


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

示例1: WritesNull

 public void WritesNull()
 {
     var sw = new StringWriter();
     var writer = new JsonWriter(sw);
     writer.WriteNull();
     Assert.AreEqual("null", sw.ToString());
 }
开发者ID:ALyman,项目名称:Liquid.Json,代码行数:7,代码来源:Primitives.cs

示例2: WriteJson

        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            EnsureReflectionObject(value.GetType());

            DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;

            string keyName = (string)_reflectionObject.GetValue(value, KeyPropertyName);
            object keyValue = _reflectionObject.GetValue(value, ValuePropertyName);

            Type keyValueType = (keyValue != null) ? keyValue.GetType() : null;

            writer.WriteStartObject();
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(KeyPropertyName) : KeyPropertyName);
            writer.WriteValue(keyName);
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(TypePropertyName) : TypePropertyName);
            writer.WriteValue((keyValueType != null) ? keyValueType.FullName : null);

            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(ValuePropertyName) : ValuePropertyName);

            if (keyValueType != null)
            {
                string valueJson;
                if (JsonSerializerInternalWriter.TryConvertToString(keyValue, keyValueType, out valueJson))
                    writer.WriteValue(valueJson);
                else
                    writer.WriteValue(keyValue);
            }
            else
            {
                writer.WriteNull();
            }

            writer.WriteEndObject();
        }
开发者ID:BgCircle,项目名称:Newtonsoft.Json,代码行数:40,代码来源:EntityKeyMemberConverter.cs

示例3: WriteJson

    /// <summary>
    /// Writes the JSON representation of the object.
    /// </summary>
    /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
    /// <param name="value">The value.</param>
    /// <param name="serializer">The calling serializer.</param>
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
      IEntityKeyMember entityKeyMember = DynamicWrapper.CreateWrapper<IEntityKeyMember>(value);
      Type keyType = (entityKeyMember.Value != null) ? entityKeyMember.Value.GetType() : null;

      writer.WriteStartObject();
      writer.WritePropertyName("Key");
      writer.WriteValue(entityKeyMember.Key);
      writer.WritePropertyName("Type");
      writer.WriteValue((keyType != null) ? keyType.FullName : null);

      writer.WritePropertyName("Value");

      if (keyType != null)
      {
        string valueJson;
        if (JsonSerializerInternalWriter.TryConvertToString(entityKeyMember.Value, keyType, out valueJson))
          writer.WriteValue(valueJson);
        else
          writer.WriteValue(entityKeyMember.Value);
      }
      else
      {
        writer.WriteNull();
      }

      writer.WriteEndObject();
    }
开发者ID:Gert-Cominotto,项目名称:MvvmCross,代码行数:34,代码来源:EntityKeyMemberConverter.cs

示例4: WriteJson

    /// <summary>
    /// Writes the JSON representation of the object.
    /// </summary>
    /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
    /// <param name="value">The value.</param>
    /// <param name="serializer">The calling serializer.</param>
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
      if (value == null)
      {
        writer.WriteNull();
        return;
      }

      Enum e = (Enum)value;

      string enumName = e.ToString("G");

      if (char.IsNumber(enumName[0]) || enumName[0] == '-')
      {
        writer.WriteValue(value);
      }
      else
      {
        BidirectionalDictionary<string, string> map = GetEnumNameMap(e.GetType());

        string resolvedEnumName;
        map.TryGetByFirst(enumName, out resolvedEnumName);
        resolvedEnumName = resolvedEnumName ?? enumName;

		if (CamelCaseText)
          resolvedEnumName = StringUtils.ToCamelCase(resolvedEnumName);

        writer.WriteValue(resolvedEnumName);
      }
    }
开发者ID:rejemy,项目名称:serverville-client-unity,代码行数:36,代码来源:StringEnumConverter.cs

示例5: ValueFormatting

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

      using (JsonWriter jsonWriter = new JsonWriter(sw))
      {
        jsonWriter.WriteStartArray();
        jsonWriter.WriteValue('@');
        jsonWriter.WriteValue("\r\n\t\f\b?{\\r\\n\"\'");
        jsonWriter.WriteValue(true);
        jsonWriter.WriteValue(10);
        jsonWriter.WriteValue(10.99);
        jsonWriter.WriteValue(0.99);
        jsonWriter.WriteValue(0.000000000000000001d);
        jsonWriter.WriteValue(0.000000000000000001m);
        jsonWriter.WriteValue(null);
        jsonWriter.WriteValue("This is a string.");
        jsonWriter.WriteNull();
        jsonWriter.WriteUndefined();
        jsonWriter.WriteEndArray();
      }

      const string expected = @"[""@"",""\r\n\t\f\b?{\\r\\n\""'"",true,10,10.99,0.99,1E-18,0.000000000000000001,,""This is a string."",null,undefined]";
      string result = sb.ToString();

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

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

示例6: WriteJson

        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            DefaultContractResolver resolver = serializer.ContractResolver as DefaultContractResolver;

            IEntityKeyMember entityKeyMember = DynamicWrapper.CreateWrapper<IEntityKeyMember>(value);
            Type keyType = (entityKeyMember.Value != null) ? entityKeyMember.Value.GetType() : null;

            writer.WriteStartObject();
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(KeyPropertyName) : KeyPropertyName);
            writer.WriteValue(entityKeyMember.Key);
            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(TypePropertyName) : TypePropertyName);
            writer.WriteValue((keyType != null) ? keyType.FullName : null);

            writer.WritePropertyName((resolver != null) ? resolver.GetResolvedPropertyName(ValuePropertyName) : ValuePropertyName);

            if (keyType != null)
            {
                string valueJson;
                if (JsonSerializerInternalWriter.TryConvertToString(entityKeyMember.Value, keyType, out valueJson))
                    writer.WriteValue(valueJson);
                else
                    writer.WriteValue(entityKeyMember.Value);
            }
            else
            {
                writer.WriteNull();
            }

            writer.WriteEndObject();
        }
开发者ID:yonglehou,项目名称:microservice_workshop,代码行数:36,代码来源:EntityKeyMemberConverter.cs

示例7: WriteJson

    /// <summary>
    /// Writes the JSON representation of the object.
    /// </summary>
    /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
    /// <param name="value">The value.</param>
    /// <param name="serializer">The calling serializer.</param>
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
      if (value == null)
      {
        writer.WriteNull();
        return;
      }

      Enum e = (Enum) value;
      string enumName = e.ToString("G");

      if (char.IsNumber(enumName[0]) || enumName[0] == '-')
      {
        // enum value didn't have an option against it
        // fallback to writing number value
        writer.WriteValue(value);
      }
      else
      {
        if (CamelCaseText)
          enumName = StringUtils.ToCamelCase(enumName);

        writer.WriteValue(enumName);
      }
    }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:31,代码来源:StringEnumConverter.cs

示例8: WriteJson

        /// <summary>
        /// Writes the JSON representation of the object.
        /// </summary>
        /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            Enum e = (Enum)value;

            string enumName = e.ToString("G");

            if (char.IsNumber(enumName[0]) || enumName[0] == '-')
            {
                // enum value has no name so write number
                writer.WriteValue(value);
            }
            else
            {
                Type enumType = e.GetType();

                string finalName = EnumUtils.ToEnumName(enumType, enumName, CamelCaseText);

                writer.WriteValue(finalName);
            }
        }
开发者ID:b-bot-110,项目名称:Newtonsoft.Json,代码行数:32,代码来源:StringEnumConverter.cs

示例9: WriteJson

    /// <summary>
    /// Writes the JSON representation of the object.
    /// </summary>
    /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
    /// <param name="value">The value.</param>
    /// <param name="serializer">The calling serializer.</param>
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
      if (value == null)
      {
        writer.WriteNull();
        return;
      }

      Enum e = (Enum)value;

      string enumName = e.ToString("G");

      if (char.IsNumber(enumName[0]) || enumName[0] == '-')
      {
        writer.WriteValue(value);
      }
      else
      {
        BidirectionalDictionary<string, string> map = GetEnumNameMap(e.GetType());

        string resolvedEnumName;
        map.TryGetByFirst(enumName, out resolvedEnumName);
        resolvedEnumName = resolvedEnumName ?? enumName;

        if (CamelCaseText)
        {
          string[] names = resolvedEnumName.Split(',').Select(item => StringUtils.ToCamelCase(item.Trim())).ToArray();
          resolvedEnumName = string.Join(", ", names);
        }

        writer.WriteValue(resolvedEnumName);
      }
    }
开发者ID:GotenXiao,项目名称:blink1,代码行数:39,代码来源:StringEnumConverter.cs

示例10: WriteJsonValue

 private void WriteJsonValue(JsonWriter writer, IJsonValue value)
 {
     switch (value.ValueType)
     {
         case JsonValueType.Array:
         {
             JsonArray a = value.GetArray();
             writer.WriteStartArray();
             for (int i = 0; i < a.Count; i++)
             {
                 WriteJsonValue(writer, a[i]);
             }
             writer.WriteEndArray();
         }
             break;
         case JsonValueType.Boolean:
         {
             writer.WriteValue(value.GetBoolean());
         }
             break;
         case JsonValueType.Null:
         {
             writer.WriteNull();
         }
             break;
         case JsonValueType.Number:
         {
             // JsonValue doesn't support integers
             // serialize whole numbers without a decimal point
             double d = value.GetNumber();
             bool isInteger = (d % 1 == 0);
             if (isInteger && d <= long.MaxValue && d >= long.MinValue)
                 writer.WriteValue(Convert.ToInt64(d));
             else
                 writer.WriteValue(d);
         }
             break;
         case JsonValueType.Object:
         {
             JsonObject o = value.GetObject();
             writer.WriteStartObject();
             foreach (KeyValuePair<string, IJsonValue> v in o)
             {
                 writer.WritePropertyName(v.Key);
                 WriteJsonValue(writer, v.Value);
             }
             writer.WriteEndObject();
         }
             break;
         case JsonValueType.String:
         {
             writer.WriteValue(value.GetString());
         }
             break;
         default:
             throw new ArgumentOutOfRangeException("ValueType");
     }
 }
开发者ID:sdgdsffdsfff,项目名称:hermes.net,代码行数:58,代码来源:JsonValueConverter.cs

示例11: WriteJson

    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
      NameContainer nameContainer = value as NameContainer;

      if (nameContainer != null)
        writer.WriteValue(nameContainer.Value);
      else
        writer.WriteNull();
    }
开发者ID:rodrigobrito,项目名称:Newtonsoft.Json,代码行数:9,代码来源:PublicParametizedConstructorRequiringConverterTestClass.cs

示例12: WriteJson

 /// <summary>
 /// Writes the JSON representation of the object.
 /// </summary>
 /// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
 /// <param name="value">The value.</param>
 /// <param name="serializer">The calling serializer.</param>
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
   if (writer == null) throw new ArgumentNullException("writer");
   if (value == null) {
     writer.WriteNull();
     return;
   }
   var data = GetByteArray(value);
   writer.WriteValue(data);
 }
开发者ID:tormoz70,项目名称:Bio.Framework.8,代码行数:15,代码来源:BinaryConverter.cs

示例13: Write

 public override void Write(JsonWriter writer, object value)
 {
     if (value == null) writer.WriteNull();
     else
     {
         var m = value as LinearRegressionModel;
         base.Write(writer, m);
         writer.WriteProperty(nameof(m.Theta), m.Theta);
     }
 }
开发者ID:sethjuarez,项目名称:numl,代码行数:10,代码来源:LinearRegressionSerializer.cs

示例14: WriteJson

 // Token: 0x0600017F RID: 383
 // RVA: 0x0002B420 File Offset: 0x00029620
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (value == null)
     {
         writer.WriteNull();
         return;
     }
     byte[] byteArray = this.GetByteArray(value);
     writer.WriteValue(byteArray);
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:12,代码来源:BinaryConverter.cs

示例15: Export

        public virtual void Export(object value, JsonWriter writer)
        {
            if (writer == null)
                throw new ArgumentNullException("writer");

            if (value == null)
                writer.WriteNull();
            else
                ExportValue(value, writer);
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:10,代码来源:JsonExporterBase.cs


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