| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Text.Json.Schema; |
| | | 6 | | |
| | | 7 | | namespace System.Text.Json.Serialization.Converters |
| | | 8 | | { |
| | | 9 | | internal sealed class DateTimeConverter : JsonPrimitiveConverter<DateTime> |
| | | 10 | | { |
| | | 11 | | public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| | 652 | 12 | | { |
| | 652 | 13 | | return reader.GetDateTime(); |
| | 0 | 14 | | } |
| | | 15 | | |
| | | 16 | | public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) |
| | 0 | 17 | | { |
| | 0 | 18 | | writer.WriteStringValue(value); |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | internal override DateTime ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerO |
| | 0 | 22 | | { |
| | 0 | 23 | | Debug.Assert(reader.TokenType == JsonTokenType.PropertyName); |
| | 0 | 24 | | return reader.GetDateTimeNoValidation(); |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions opti |
| | 0 | 28 | | { |
| | 0 | 29 | | writer.WritePropertyName(value); |
| | 0 | 30 | | } |
| | | 31 | | |
| | 0 | 32 | | internal override JsonSchema? GetSchema(JsonNumberHandling _) => new JsonSchema { Type = JsonSchemaType.String, |
| | | 33 | | } |
| | | 34 | | } |