public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
                return null;

            if (reader.TokenType == JsonToken.Date)
            {
                if (objectType == typeof(DateTimeOffset))
                    return reader.Value is DateTimeOffset ? reader.Value : new DateTimeOffset((DateTime)reader.Value);

                return reader.Value;
            }

            if (reader.TokenType != JsonToken.String)
                throw new Exception(string.Format("Unexpected token parsing date. Expected String, got {0}.",reader.TokenType.ToString()));


            var time = reader.Value as string;

            if (time == null)
                return null;
            
            if (objectType == typeof(DateTime) || objectType == typeof(DateTime?))
            {
                return DateTime.Parse(time,CultureInfo.InvariantCulture,DateTimeStyles.RoundtripKind);
            }

            if (objectType == typeof(DateTimeOffset) || objectType == typeof(DateTimeOffset?))
            {
                return DateTimeOffset.Parse(time, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
            }

            return null;
        }
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
 {
     throw new NotImplementedException("just need serialization");
 }
        internal void WriteToken(JsonReader reader, int initialDepth, bool writeChildren, bool writeDateConstructorAsDate)
        {
            do
            {
                switch (reader.TokenType)
                {
                    case JsonToken.None:
                        // read to next
                        break;
                    case JsonToken.StartObject:
                        WriteStartObject();
                        break;
                    case JsonToken.StartArray:
                        WriteStartArray();
                        break;
                    case JsonToken.StartConstructor:
                        string constructorName = reader.Value.ToString();
                        // write a JValue date when the constructor is for a date
                        if (writeDateConstructorAsDate && string.Equals(constructorName, "Date", StringComparison.Ordinal))
                            WriteConstructorDate(reader);
                        else
                            WriteStartConstructor(reader.Value.ToString());
                        break;
                    case JsonToken.PropertyName:
                        WritePropertyName(reader.Value.ToString());
                        break;
                    case JsonToken.Comment:
                        WriteComment((reader.Value != null) ? reader.Value.ToString() : null);
                        break;
                    case JsonToken.Integer:
#if !(NET20 || NET35 || PORTABLE || PORTABLE40)
                        if (reader.Value is BigInteger)
                        {
                            WriteValue((BigInteger)reader.Value);
                        }
                        else
#endif
                        {
                            WriteValue(Convert.ToInt64(reader.Value, CultureInfo.InvariantCulture));
                        }
                        break;
                    case JsonToken.Float:
                        object value = reader.Value;

                        if (value is decimal)
                            WriteValue((decimal)value);
                        else if (value is double)
                            WriteValue((double)value);
                        else if (value is float)
                            WriteValue((float)value);
                        else
                            WriteValue(Convert.ToDouble(value, CultureInfo.InvariantCulture));
                        break;
                    case JsonToken.String:
                        WriteValue(reader.Value.ToString());
                        break;
                    case JsonToken.Boolean:
                        WriteValue(Convert.ToBoolean(reader.Value, CultureInfo.InvariantCulture));
                        break;
                    case JsonToken.Null:
                        WriteNull();
                        break;
                    case JsonToken.Undefined:
                        WriteUndefined();
                        break;
                    case JsonToken.EndObject:
                        WriteEndObject();
                        break;
                    case JsonToken.EndArray:
                        WriteEndArray();
                        break;
                    case JsonToken.EndConstructor:
                        WriteEndConstructor();
                        break;
                    case JsonToken.Date:
#if !NET20
                        if (reader.Value is DateTimeOffset)
                            WriteValue((DateTimeOffset)reader.Value);
                        else
#endif
                            WriteValue(Convert.ToDateTime(reader.Value, CultureInfo.InvariantCulture));
                        break;
                    case JsonToken.Raw:
                        WriteRawValue((reader.Value != null) ? reader.Value.ToString() : null);
                        break;
                    case JsonToken.Bytes:
                        if (reader.Value is Guid)
                            WriteValue((Guid)reader.Value);
                        else
                            WriteValue((byte[])reader.Value);
                        break;
                    default:
                        throw MiscellaneousUtils.CreateArgumentOutOfRangeException("TokenType", reader.TokenType, "Unexpected token type.");
                }
            } while (
                // stop if we have reached the end of the token being read
                initialDepth - 1 < reader.Depth - (IsEndToken(reader.TokenType) ? 1 : 0)
                && writeChildren
                && reader.Read());
        }
        private void WriteConstructorDate(JsonReader reader)
        {
            if (!reader.Read())
                throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", null);
            if (reader.TokenType != JsonToken.Integer)
                throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected Integer, got " + reader.TokenType, null);

            long ticks = (long)reader.Value;
            DateTime date = DateTimeUtils.ConvertJavaScriptTicksToDateTime(ticks);

            if (!reader.Read())
                throw JsonWriterException.Create(this, "Unexpected end when reading date constructor.", null);
            if (reader.TokenType != JsonToken.EndConstructor)
                throw JsonWriterException.Create(this, "Unexpected token when reading date constructor. Expected EndConstructor, got " + reader.TokenType, null);

            WriteValue(date);
        }
        internal void WriteToken(JsonReader reader, bool writeChildren, bool writeDateConstructorAsDate)
        {
            int initialDepth;

            if (reader.TokenType == JsonToken.None)
                initialDepth = -1;
            else if (!IsStartToken(reader.TokenType))
                initialDepth = reader.Depth + 1;
            else
                initialDepth = reader.Depth;

            WriteToken(reader, initialDepth, writeChildren, writeDateConstructorAsDate);
        }
        /// <summary>
        /// Writes the current <see cref="JsonReader"/> token.
        /// </summary>
        /// <param name="reader">The <see cref="JsonReader"/> to read the token from.</param>
        /// <param name="writeChildren">A flag indicating whether the current token's children should be written.</param>
        public void WriteToken(JsonReader reader, bool writeChildren)
        {
            ValidationUtils.ArgumentNotNull(reader, "reader");

            WriteToken(reader, writeChildren, true);
        }
 /// <summary>
 /// Writes the current <see cref="JsonReader"/> token and its children.
 /// </summary>
 /// <param name="reader">The <see cref="JsonReader"/> to read the token from.</param>
 public void WriteToken(JsonReader reader)
 {
     WriteToken(reader, true, true);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="JsonValidatingReader"/> class that
 /// validates the content returned from the given <see cref="JsonReader"/>.
 /// </summary>
 /// <param name="reader">The <see cref="JsonReader"/> to read from while validating.</param>
 public JsonValidatingReader(JsonReader reader)
 {
     ValidationUtils.ArgumentNotNull(reader, "reader");
     _reader = reader;
     _stack = new Stack<SchemaScope>();
 }
 /// <summary>
 /// Reads the JSON representation of the object.
 /// </summary>
 /// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
 /// <param name="objectType">Type of the object.</param>
 /// <param name="existingValue">The existing value of object being read.</param>
 /// <param name="serializer">The calling serializer.</param>
 /// <returns>The object value.</returns>
 public abstract object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer);