Rename JsonSerializer.Read\Write.cs to JsonConverterOfT.Read\WriteCore.cs
authorSteve Harter <steveharter@users.noreply.github.com>
Fri, 21 Feb 2020 18:37:22 +0000 (12:37 -0600)
committerSteve Harter <steveharter@users.noreply.github.com>
Wed, 4 Mar 2020 20:09:34 +0000 (14:09 -0600)
src/libraries/System.Text.Json/src/System.Text.Json.csproj
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.WriteCore.cs [new file with mode: 0644]
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.cs [deleted file]
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.cs [deleted file]

index 68bf3d616528baeee96031f55910ad90cb6bee06..461572bf70c7e9659f2d6cb48e70dae0a5d33680 100644 (file)
     <Compile Include="System\Text\Json\Serialization\JsonConverterAttribute.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonConverterFactory.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonConverterOfT.cs" />
+    <Compile Include="System\Text\Json\Serialization\JsonConverterOfT.ReadCore.cs" />
+    <Compile Include="System\Text\Json\Serialization\JsonConverterOfT.WriteCore.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonDefaultNamingPolicy.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonDictionaryConverter.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonExtensionDataAttribute.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonPropertyInfoOfTTypeToConvert.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonPropertyNameAttribute.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonResumableConverterOfT.cs" />
-    <Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandleMetadata.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.HandlePropertyName.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.Helpers.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.String.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Read.Utf8JsonReader.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.ByteArray.cs" />
-    <Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.HandleMetadata.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.Helpers.cs" />
     <Compile Include="System\Text\Json\Serialization\JsonSerializer.Write.Stream.cs" />
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.ReadCore.cs
new file mode 100644 (file)
index 0000000..50deaa6
--- /dev/null
@@ -0,0 +1,114 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Buffers;
+using System.Diagnostics;
+using System.Text.Json.Serialization;
+
+namespace System.Text.Json
+{
+    /// <summary>
+    /// Provides functionality to serialize objects or value types to JSON and
+    /// deserialize JSON into objects or value types.
+    /// </summary>
+    public static partial class JsonSerializer
+    {
+        private static void ReadCore(
+            JsonSerializerOptions options,
+            ref Utf8JsonReader reader,
+            ref ReadStack state)
+        {
+            try
+            {
+                JsonPropertyInfo jsonPropertyInfo = state.Current.JsonClassInfo!.PolicyProperty!;
+                JsonConverter converter = jsonPropertyInfo.ConverterBase;
+
+                if (!state.IsContinuation)
+                {
+                    if (!JsonConverter.SingleValueReadWithReadAhead(converter.ClassType, ref reader, ref state))
+                    {
+                        // Read more data until we have the full element.
+                        state.BytesConsumed += reader.BytesConsumed;
+                        return;
+                    }
+                }
+                else
+                {
+                    // For a continuation, read ahead here to avoid having to build and then tear
+                    // down the call stack if there is more than one buffer fetch necessary.
+                    if (!JsonConverter.SingleValueReadWithReadAhead(ClassType.Value, ref reader, ref state))
+                    {
+                        state.BytesConsumed += reader.BytesConsumed;
+                        return;
+                    }
+                }
+
+                bool success = converter.TryReadAsObject(ref reader, jsonPropertyInfo.RuntimePropertyType!, options, ref state, out object? value);
+                if (success)
+                {
+                    state.Current.ReturnValue = value;
+
+                    // Read any trailing whitespace.
+                    // If additional whitespace exists after this read, the subsequent call to reader.Read() will throw.
+                    reader.Read();
+                }
+
+                state.BytesConsumed += reader.BytesConsumed;
+            }
+            catch (JsonReaderException ex)
+            {
+                // Re-throw with Path information.
+                ThrowHelper.ReThrowWithPath(state, ex);
+            }
+            catch (FormatException ex) when (ex.Source == ThrowHelper.ExceptionSourceValueToRethrowAsJsonException)
+            {
+                ThrowHelper.ReThrowWithPath(state, reader, ex);
+            }
+            catch (InvalidOperationException ex) when (ex.Source == ThrowHelper.ExceptionSourceValueToRethrowAsJsonException)
+            {
+                ThrowHelper.ReThrowWithPath(state, reader, ex);
+            }
+            catch (JsonException ex)
+            {
+                ThrowHelper.AddExceptionInformation(state, reader, ex);
+                throw;
+            }
+        }
+
+        internal static object? ReadCoreReEntry(
+            JsonSerializerOptions options,
+            ref Utf8JsonReader reader,
+            ref ReadStack state)
+        {
+            JsonPropertyInfo jsonPropertyInfo = state.Current.JsonPropertyInfo!;
+            JsonConverter converter = jsonPropertyInfo.ConverterBase;
+            bool success = converter.TryReadAsObject(ref reader, jsonPropertyInfo.RuntimePropertyType!, options, ref state, out object? value);
+            Debug.Assert(success);
+            return value;
+        }
+
+        private static ReadOnlySpan<byte> GetUnescapedString(ReadOnlySpan<byte> utf8Source, int idx)
+        {
+            // The escaped name is always longer than the unescaped, so it is safe to use escaped name for the buffer length.
+            int length = utf8Source.Length;
+            byte[]? pooledName = null;
+
+            Span<byte> unescapedName = length <= JsonConstants.StackallocThreshold ?
+                stackalloc byte[length] :
+                (pooledName = ArrayPool<byte>.Shared.Rent(length));
+
+            JsonReaderHelper.Unescape(utf8Source, unescapedName, idx, out int written);
+            ReadOnlySpan<byte> propertyName = unescapedName.Slice(0, written).ToArray();
+
+            if (pooledName != null)
+            {
+                // We clear the array because it is "user data" (although a property name).
+                new Span<byte>(pooledName, 0, written).Clear();
+                ArrayPool<byte>.Shared.Return(pooledName);
+            }
+
+            return propertyName;
+        }
+    }
+}
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.WriteCore.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.WriteCore.cs
new file mode 100644 (file)
index 0000000..a1999ac
--- /dev/null
@@ -0,0 +1,38 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.Text.Json.Serialization;
+
+namespace System.Text.Json
+{
+    public static partial class JsonSerializer
+    {
+        // There are three conditions to consider for an object (primitive value, enumerable or object) being processed here:
+        // 1) The object type was specified as the root-level return type to a Deserialize method.
+        // 2) The object is a property on a parent object.
+        // 3) The object is an element in an enumerable.
+        private static bool WriteCore(
+            Utf8JsonWriter writer,
+            object? value,
+            JsonSerializerOptions options,
+            ref WriteStack state,
+            JsonConverter jsonConverter)
+        {
+            try
+            {
+                return jsonConverter.TryWriteAsObject(writer, value, options, ref state);
+            }
+            catch (InvalidOperationException ex) when (ex.Source == ThrowHelper.ExceptionSourceValueToRethrowAsJsonException)
+            {
+                ThrowHelper.ReThrowWithPath(state, ex);
+                throw;
+            }
+            catch (JsonException ex)
+            {
+                ThrowHelper.AddExceptionInformation(state, ex);
+                throw;
+            }
+        }
+    }
+}
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Read.cs
deleted file mode 100644 (file)
index 50deaa6..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Buffers;
-using System.Diagnostics;
-using System.Text.Json.Serialization;
-
-namespace System.Text.Json
-{
-    /// <summary>
-    /// Provides functionality to serialize objects or value types to JSON and
-    /// deserialize JSON into objects or value types.
-    /// </summary>
-    public static partial class JsonSerializer
-    {
-        private static void ReadCore(
-            JsonSerializerOptions options,
-            ref Utf8JsonReader reader,
-            ref ReadStack state)
-        {
-            try
-            {
-                JsonPropertyInfo jsonPropertyInfo = state.Current.JsonClassInfo!.PolicyProperty!;
-                JsonConverter converter = jsonPropertyInfo.ConverterBase;
-
-                if (!state.IsContinuation)
-                {
-                    if (!JsonConverter.SingleValueReadWithReadAhead(converter.ClassType, ref reader, ref state))
-                    {
-                        // Read more data until we have the full element.
-                        state.BytesConsumed += reader.BytesConsumed;
-                        return;
-                    }
-                }
-                else
-                {
-                    // For a continuation, read ahead here to avoid having to build and then tear
-                    // down the call stack if there is more than one buffer fetch necessary.
-                    if (!JsonConverter.SingleValueReadWithReadAhead(ClassType.Value, ref reader, ref state))
-                    {
-                        state.BytesConsumed += reader.BytesConsumed;
-                        return;
-                    }
-                }
-
-                bool success = converter.TryReadAsObject(ref reader, jsonPropertyInfo.RuntimePropertyType!, options, ref state, out object? value);
-                if (success)
-                {
-                    state.Current.ReturnValue = value;
-
-                    // Read any trailing whitespace.
-                    // If additional whitespace exists after this read, the subsequent call to reader.Read() will throw.
-                    reader.Read();
-                }
-
-                state.BytesConsumed += reader.BytesConsumed;
-            }
-            catch (JsonReaderException ex)
-            {
-                // Re-throw with Path information.
-                ThrowHelper.ReThrowWithPath(state, ex);
-            }
-            catch (FormatException ex) when (ex.Source == ThrowHelper.ExceptionSourceValueToRethrowAsJsonException)
-            {
-                ThrowHelper.ReThrowWithPath(state, reader, ex);
-            }
-            catch (InvalidOperationException ex) when (ex.Source == ThrowHelper.ExceptionSourceValueToRethrowAsJsonException)
-            {
-                ThrowHelper.ReThrowWithPath(state, reader, ex);
-            }
-            catch (JsonException ex)
-            {
-                ThrowHelper.AddExceptionInformation(state, reader, ex);
-                throw;
-            }
-        }
-
-        internal static object? ReadCoreReEntry(
-            JsonSerializerOptions options,
-            ref Utf8JsonReader reader,
-            ref ReadStack state)
-        {
-            JsonPropertyInfo jsonPropertyInfo = state.Current.JsonPropertyInfo!;
-            JsonConverter converter = jsonPropertyInfo.ConverterBase;
-            bool success = converter.TryReadAsObject(ref reader, jsonPropertyInfo.RuntimePropertyType!, options, ref state, out object? value);
-            Debug.Assert(success);
-            return value;
-        }
-
-        private static ReadOnlySpan<byte> GetUnescapedString(ReadOnlySpan<byte> utf8Source, int idx)
-        {
-            // The escaped name is always longer than the unescaped, so it is safe to use escaped name for the buffer length.
-            int length = utf8Source.Length;
-            byte[]? pooledName = null;
-
-            Span<byte> unescapedName = length <= JsonConstants.StackallocThreshold ?
-                stackalloc byte[length] :
-                (pooledName = ArrayPool<byte>.Shared.Rent(length));
-
-            JsonReaderHelper.Unescape(utf8Source, unescapedName, idx, out int written);
-            ReadOnlySpan<byte> propertyName = unescapedName.Slice(0, written).ToArray();
-
-            if (pooledName != null)
-            {
-                // We clear the array because it is "user data" (although a property name).
-                new Span<byte>(pooledName, 0, written).Clear();
-                ArrayPool<byte>.Shared.Return(pooledName);
-            }
-
-            return propertyName;
-        }
-    }
-}
diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonSerializer.Write.cs
deleted file mode 100644 (file)
index a1999ac..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System.Text.Json.Serialization;
-
-namespace System.Text.Json
-{
-    public static partial class JsonSerializer
-    {
-        // There are three conditions to consider for an object (primitive value, enumerable or object) being processed here:
-        // 1) The object type was specified as the root-level return type to a Deserialize method.
-        // 2) The object is a property on a parent object.
-        // 3) The object is an element in an enumerable.
-        private static bool WriteCore(
-            Utf8JsonWriter writer,
-            object? value,
-            JsonSerializerOptions options,
-            ref WriteStack state,
-            JsonConverter jsonConverter)
-        {
-            try
-            {
-                return jsonConverter.TryWriteAsObject(writer, value, options, ref state);
-            }
-            catch (InvalidOperationException ex) when (ex.Source == ThrowHelper.ExceptionSourceValueToRethrowAsJsonException)
-            {
-                ThrowHelper.ReThrowWithPath(state, ex);
-                throw;
-            }
-            catch (JsonException ex)
-            {
-                ThrowHelper.AddExceptionInformation(state, ex);
-                throw;
-            }
-        }
-    }
-}