| | | 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 DateTimeOffsetConverter : JsonPrimitiveConverter<DateTimeOffset> |
| | | 10 | | { |
| | | 11 | | public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options |
| | 680 | 12 | | { |
| | 680 | 13 | | return reader.GetDateTimeOffset(); |
| | 0 | 14 | | } |
| | | 15 | | |
| | | 16 | | public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) |
| | 0 | 17 | | { |
| | 0 | 18 | | writer.WriteStringValue(value); |
| | 0 | 19 | | } |
| | | 20 | | |
| | | 21 | | internal override DateTimeOffset ReadAsPropertyNameCore(ref Utf8JsonReader reader, Type typeToConvert, JsonSeria |
| | 0 | 22 | | { |
| | 0 | 23 | | Debug.Assert(reader.TokenType == JsonTokenType.PropertyName); |
| | 0 | 24 | | return reader.GetDateTimeOffsetNoValidation(); |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | internal override void WriteAsPropertyNameCore(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOption |
| | 0 | 28 | | { |
| | 0 | 29 | | writer.WritePropertyName(value); |
| | 0 | 30 | | } |
| | | 31 | | |
| | 0 | 32 | | internal override JsonSchema? GetSchema(JsonNumberHandling _) => new JsonSchema { Type = JsonSchemaType.String, |
| | | 33 | | } |
| | | 34 | | } |