Newtonsoft.Json.JsonReader.ReadAsDateTimeOffset C# (CSharp) Method

ReadAsDateTimeOffset() public method

Reads the next JSON token from the stream as a Nullable{T} of DateTimeOffset.
public ReadAsDateTimeOffset ( ) : DateTimeOffset?
return DateTimeOffset?
        public virtual DateTimeOffset? ReadAsDateTimeOffset()
        {
            JsonToken t = GetContentToken();

            switch (t)
            {
                case JsonToken.None:
                case JsonToken.Null:
                case JsonToken.EndArray:
                    return null;
                case JsonToken.Date:
                    if (Value is DateTime)
                    {
                        SetToken(JsonToken.Date, new DateTimeOffset((DateTime)Value), false);
                    }

                    return (DateTimeOffset)Value;
                case JsonToken.String:
                    string s = (string)Value;
                    return ReadDateTimeOffsetString(s);
                default:
                    throw JsonReaderException.Create(this, "Error reading date. Unexpected token: {0}.".FormatWith(CultureInfo.InvariantCulture, t));
            }
        }

Usage Example

コード例 #1
0
ファイル: JsonValidatingReader.cs プロジェクト: cinemyp/R440O
        /// <summary>
        /// Reads the next JSON token from the stream as a <see cref="Nullable{DateTimeOffset}"/>.
        /// </summary>
        /// <returns>A <see cref="Nullable{DateTimeOffset}"/>.</returns>
        public override DateTimeOffset?ReadAsDateTimeOffset()
        {
            DateTimeOffset?dateTimeOffset = _reader.ReadAsDateTimeOffset();

            ValidateCurrentToken();
            return(dateTimeOffset);
        }
All Usage Examples Of Newtonsoft.Json.JsonReader::ReadAsDateTimeOffset