本文整理汇总了C#中Newtonsoft.Json.JsonWriter.WriteStartConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# JsonWriter.WriteStartConstructor方法的具体用法?C# JsonWriter.WriteStartConstructor怎么用?C# JsonWriter.WriteStartConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonWriter
的用法示例。
在下文中一共展示了JsonWriter.WriteStartConstructor方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
{
long ticks;
if (value is DateTime)
{
DateTime dateTime = (DateTime)value;
DateTime utcDateTime = dateTime.ToUniversalTime();
ticks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(utcDateTime);
}
#if !NET20
else if (value is DateTimeOffset)
{
DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
DateTimeOffset utcDateTimeOffset = dateTimeOffset.ToUniversalTime();
ticks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(utcDateTimeOffset.UtcDateTime);
}
#endif
else
{
throw new JsonSerializationException("Expected date object value.");
}
writer.WriteStartConstructor("Date");
writer.WriteValue(ticks);
writer.WriteEndConstructor();
}
示例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)
{
String isoDateTimeString;
if (value is DateTime)
{
DateTime dateTime = (DateTime)value;
if ((DateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
|| (DateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
dateTime = dateTime.ToUniversalTime();
isoDateTimeString = dateTime.ToString(DefaultDateTimeFormat);
}
#if !PocketPC && !NET20
else if (value is DateTimeOffset)
{
DateTimeOffset dateTimeOffset = (DateTimeOffset)value;
if ((DateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal
|| (DateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal)
dateTimeOffset = dateTimeOffset.ToUniversalTime();
isoDateTimeString = dateTimeOffset.ToString(DefaultDateTimeFormat);
}
#endif
else
{
throw new Exception("Expected date object value.");
}
writer.WriteStartConstructor("Date");
writer.WriteValue(isoDateTimeString);
writer.WriteEndConstructor();
}
示例3: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (!(value is DateTime))
throw new JsonSerializationException("Expected date object value.");
long num = JsonConvert.ConvertDateTimeToJavaScriptTicks(((DateTime) value).ToUniversalTime());
writer.WriteStartConstructor("Date");
writer.WriteValue(num);
writer.WriteEndConstructor();
}
示例4: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
if (value is DateTime)
{
DateTime date = (DateTime)value;
if (date.Equals(DateTime.MinValue))
{
writer.WriteRawValue("null");
}
else
{
string template = (date.TimeOfDay == new TimeSpan(0, 0, 0)) ? "{0},{1},{2}" : "{0},{1},{2},{3},{4},{5}";
writer.WriteStartConstructor("Date");
writer.WriteRawValue(
string.Format(template, date.Year, date.Month - 1, date.Day,
date.Hour, date.Minute, date.Second));
writer.WriteEndConstructor();
}
}
}
示例5: WriteJson
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
string v;
if (value != null && !string.IsNullOrEmpty((v = value.ToString( ))))
{
if (System.Text.RegularExpressions.Regex.IsMatch(v, @"\[*\]"))
{
writer.WriteRawValue(v);
}
else if (System.Text.RegularExpressions.Regex.IsMatch(v, @"\{*\}"))
{
writer.WriteRawValue(v);
}
else
{
writer.WriteStartConstructor(value.ToString( ));
writer.WriteEndConstructor( );
}
}
else
writer.WriteNull( );
}
示例6: WriteTo
public override void WriteTo(JsonWriter writer, params JsonConverter[] converters)
{
writer.WriteStartConstructor(this._name);
foreach (JToken jtoken in this.Children())
jtoken.WriteTo(writer, converters);
writer.WriteEndConstructor();
}