本文整理汇总了C#中Newtonsoft.Json.JsonReader.ReadAsDateTime方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ReadAsDateTime方法的具体用法?C# JsonReader.ReadAsDateTime怎么用?C# JsonReader.ReadAsDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.ReadAsDateTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadDateToken
/// <summary>
/// Reads a date token from a JSON reader
/// </summary>
/// <param name="reader">json reader</param>
/// <param name="objectType">object type</param>
/// <returns>date object</returns>
private object ReadDateToken(JsonReader reader, Type objectType)
{
if (objectType == typeof(DateTimeOffset?) && reader.TokenType == JsonToken.Null)
return null;
if (reader.TokenType == JsonToken.Date)
{
return reader.ReadAsDateTime();
}
if (reader.TokenType != JsonToken.Integer)
{
throw new ArgumentException($"Expecting token of type '{JsonToken.Integer}', and found a token of type {reader.TokenType}.");
}
var value = Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture);
if (_isMilliseconds)
{
return GetUtcDateFromUnixTimeMilliseconds(value);
}
else
{
return GetUtcDateFromUnixTimeSeconds(value);
}
}
示例2: ReadByDataType
private static void ReadByDataType(JsonReader reader, DataType dataType)
{
switch (dataType)
{
case DataType.String:
reader.ReadAsString();
break;
case DataType.Int16:
case DataType.Int32:
reader.ReadAsInt32();
break;
case DataType.ByteArray:
reader.ReadAsBytes();
break;
case DataType.Decimal:
reader.ReadAsDecimal();
break;
case DataType.DateTime:
reader.ReadAsDateTime();
break;
// These types are dealt with, but there's no explicit reader method for them
// so we just have to trust that it does the right thing.
case DataType.Byte:
case DataType.Int64:
case DataType.Boolean:
case DataType.Float:
case DataType.Double:
reader.Read();
break;
}
}
示例3: ReadForType
private bool ReadForType(JsonReader reader, JsonContract contract, bool hasConverter)
{
if (hasConverter)
return reader.Read();
switch (contract != null ? (int) contract.InternalReadType : 0)
{
case 0:
while (reader.Read())
{
if (reader.TokenType != JsonToken.Comment)
return true;
}
return false;
case 1:
reader.ReadAsInt32();
break;
case 2:
reader.ReadAsBytes();
break;
case 3:
reader.ReadAsString();
break;
case 4:
reader.ReadAsDecimal();
break;
case 5:
reader.ReadAsDateTime();
break;
default:
throw new ArgumentOutOfRangeException();
}
return reader.TokenType != JsonToken.None;
}