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


C# JsonWriter.WriteNull方法代码示例

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


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

示例1: WriteJson

		/// <summary>
		/// Writes the JSON representation of the object.
		/// </summary>
		/// <param name="writer">The <see cref="T:Raven.Imports.Newtonsoft.Json.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();
			else
				writer.WriteValue(value.ToString());
		}
开发者ID:royra,项目名称:ravendb,代码行数:13,代码来源:JsonEnumConverter.cs

示例2: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var collection = (NameValueCollection)value;

			writer.WriteStartObject();

			foreach (var key in collection.AllKeys)
			{
				writer.WritePropertyName(key);

				var values = collection.GetValues(key);
				if (values == null)
				{
					writer.WriteNull();
					continue;
				}
				if (values.Length == 1)
				{
					writer.WriteValue(values[0]);
				}
				else
				{
					writer.WriteStartArray();

					foreach (var item in values)
					{
						writer.WriteValue(item);
					}

					writer.WriteEndArray();
				}

			}
			writer.WriteEndObject();
		}
开发者ID:randacc,项目名称:ravendb,代码行数:35,代码来源:NameValueCollectionJsonConverter.cs

示例3: WriteJson

		/// <summary>
		/// Writes the JSON representation of the object.
		/// </summary>
		/// <param name="writer">The <see cref="T:Raven.Imports.Newtonsoft.Json.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;
			}
			if (value.GetType() == typeof (object))
			{
				writer.WriteStartObject();
				writer.WriteEndObject();
				return;
			}

			var dynamicValue = ((IDynamicMetaObjectProvider) value).GetMetaObject(Expression.Constant(value));

			writer.WriteStartObject();
			foreach (var dynamicMemberName in dynamicValue.GetDynamicMemberNames())
			{
				writer.WritePropertyName(dynamicMemberName);
				var memberValue = DynamicUtil.GetValueDynamically(value, dynamicMemberName);
				if(memberValue == null || memberValue is ValueType || memberValue is string)
					writer.WriteValue(memberValue);
				else
					serializer.Serialize(writer, memberValue);
			}
			writer.WriteEndObject();

		}
开发者ID:925coder,项目名称:ravendb,代码行数:35,代码来源:JsonDynamicConverter.cs

示例4: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var etag = value as Etag;
     if (etag == null)
         writer.WriteNull();
     else
         writer.WriteValue(etag.ToString());
 }
开发者ID:j2jensen,项目名称:ravendb,代码行数:8,代码来源:EtagJsonConverter.cs

示例5: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			if (value is RavenJToken)
				((RavenJToken)value).WriteTo(writer);
			else if(value is DynamicNullObject)
				writer.WriteNull();
			else
				((IDynamicJsonObject)value).WriteTo(writer);
		}
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:9,代码来源:JsonToJsonConverter.cs

示例6: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			if(value == null)
			{
				writer.WriteNull();
				return;
			}
			var f = (float)value;
			writer.WriteValue(EnsureDecimalPlace(f, f.ToString("R", CultureInfo.InvariantCulture)));
		}
开发者ID:royra,项目名称:ravendb,代码行数:10,代码来源:JsonFloatConverter.cs

示例7: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			if (value is RavenJToken)
				((RavenJToken)value).WriteTo(writer);
#if !NET35
			else if(value is DynamicNullObject)
				writer.WriteNull();
			else
				((IDynamicJsonObject)value).Inner.WriteTo(writer);
#else
			throw new NotImplementedException();
#endif
		}
开发者ID:royra,项目名称:ravendb,代码行数:13,代码来源:JsonToJsonConverter.cs

示例8: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var coordinate = value as Coordinate;

            if (coordinate == null)
            {
                writer.WriteNull();
                return;
            }

            writer.WriteStartArray();
            writer.WriteValue(coordinate.Longitude);
            writer.WriteValue(coordinate.Latitude);
            if (coordinate.Is3D || coordinate.IsMeasured)
                writer.WriteValue(((Is3D)coordinate).Elevation);
            if (coordinate.IsMeasured)
                writer.WriteValue(((IsMeasured)coordinate).Measure);
            writer.WriteEndArray();
        }
开发者ID:asapostolov,项目名称:Geo,代码行数:19,代码来源:CoordinateConverter.cs

示例9: WriteValue


//.........这里部分代码省略.........
                case PrimitiveTypeCode.UInt64:
                    writer.WriteValue((ulong)value);
                    break;
                case PrimitiveTypeCode.UInt64Nullable:
                    writer.WriteValue((value == null) ? (ulong?)null : (ulong)value);
                    break;
                case PrimitiveTypeCode.Single:
                    writer.WriteValue((float)value);
                    break;
                case PrimitiveTypeCode.SingleNullable:
                    writer.WriteValue((value == null) ? (float?)null : (float)value);
                    break;
                case PrimitiveTypeCode.Double:
                    writer.WriteValue((double)value);
                    break;
                case PrimitiveTypeCode.DoubleNullable:
                    writer.WriteValue((value == null) ? (double?)null : (double)value);
                    break;
                case PrimitiveTypeCode.DateTime:
                    writer.WriteValue((DateTime)value);
                    break;
                case PrimitiveTypeCode.DateTimeNullable:
                    writer.WriteValue((value == null) ? (DateTime?)null : (DateTime)value);
                    break;
#if !NET20
                case PrimitiveTypeCode.DateTimeOffset:
                    writer.WriteValue((DateTimeOffset)value);
                    break;
                case PrimitiveTypeCode.DateTimeOffsetNullable:
                    writer.WriteValue((value == null) ? (DateTimeOffset?)null : (DateTimeOffset)value);
                    break;
#endif
                case PrimitiveTypeCode.Decimal:
                    writer.WriteValue((decimal)value);
                    break;
                case PrimitiveTypeCode.DecimalNullable:
                    writer.WriteValue((value == null) ? (decimal?)null : (decimal)value);
                    break;
                case PrimitiveTypeCode.Guid:
                    writer.WriteValue((Guid)value);
                    break;
                case PrimitiveTypeCode.GuidNullable:
                    writer.WriteValue((value == null) ? (Guid?)null : (Guid)value);
                    break;
                case PrimitiveTypeCode.TimeSpan:
                    writer.WriteValue((TimeSpan)value);
                    break;
                case PrimitiveTypeCode.TimeSpanNullable:
                    writer.WriteValue((value == null) ? (TimeSpan?)null : (TimeSpan)value);
                    break;
#if !(PORTABLE || PORTABLE40 || NET35 || NET20)
                case PrimitiveTypeCode.BigInteger:
                    // this will call to WriteValue(object)
                    writer.WriteValue((BigInteger)value);
                    break;
                case PrimitiveTypeCode.BigIntegerNullable:
                    // this will call to WriteValue(object)
                    writer.WriteValue((value == null) ? (BigInteger?)null : (BigInteger)value);
                    break;
#endif
                case PrimitiveTypeCode.Uri:
                    writer.WriteValue((Uri)value);
                    break;
                case PrimitiveTypeCode.String:
                    writer.WriteValue((string)value);
                    break;
                case PrimitiveTypeCode.Bytes:
                    writer.WriteValue((byte[])value);
                    break;
#if !(PORTABLE || NETFX_CORE)
                case PrimitiveTypeCode.DBNull:
                    writer.WriteNull();
                    break;
#endif
                default:
#if !(PORTABLE || NETFX_CORE)
                    if (value is IConvertible)
                    {
                        // the value is a non-standard IConvertible
                        // convert to the underlying value and retry
                        IConvertible convertable = (IConvertible)value;

                        TypeInformation typeInformation = ConvertUtils.GetTypeInformation(convertable);

                        // if convertable has an underlying typecode of Object then attempt to convert it to a string
                        PrimitiveTypeCode resolvedTypeCode = (typeInformation.TypeCode == PrimitiveTypeCode.Object) ? PrimitiveTypeCode.String : typeInformation.TypeCode;
                        Type resolvedType = (typeInformation.TypeCode == PrimitiveTypeCode.Object) ? typeof(string) : typeInformation.Type;

                        object convertedValue = convertable.ToType(resolvedType, CultureInfo.InvariantCulture);

                        WriteValue(writer, resolvedTypeCode, convertedValue);
                        break;
                    }
                    else
#endif
                    {
                        throw CreateUnsupportedTypeException(writer, value);
                    }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:101,代码来源:JsonWriter.cs


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