}
break;
default:
- Debug.Fail("We shouldn't be here if there are more than 4 parameters.");
+ Debug.Fail("More than 4 params: we should be in override for LargeObjectWithParameterizedConstructorConverter.");
throw new InvalidOperationException();
}
arguments.Arg3 = ((JsonParameterInfo<TArg3>)parameterInfo).TypedDefaultValue!;
break;
default:
- Debug.Fail("We shouldn't be here if there are more than 4 parameters.");
+ Debug.Fail("More than 4 params: we should be in override for LargeObjectWithParameterizedConstructorConverter.");
throw new InvalidOperationException();
}
}
if (!state.SupportContinuation && !shouldReadPreservedReferences)
{
- // Fast path that avoids maintaining state variables and dealing with preserved references.
+ // Fast path that avoids maintaining state variables.
ReadOnlySpan<byte> originalSpan = reader.OriginalSpan;
}
else
{
- // Slower path that supports continuation and preserved references.
+ // Slower path that supports continuation.
if (state.Current.ObjectState == StackFrameObjectState.None)
{
internal override JsonPropertyInfo CreateJsonPropertyInfo()
{
+ Debug.Fail("We should never get here.");
+
throw new InvalidOperationException();
}
internal override JsonParameterInfo CreateJsonParameterInfo()
{
+ Debug.Fail("We should never get here.");
+
throw new InvalidOperationException();
}
JsonSerializerOptions options,
ref ReadStack state)
{
- // We should never get here.
- Debug.Assert(false);
+ Debug.Fail("We should never get here.");
throw new InvalidOperationException();
}
JsonSerializerOptions options,
ref WriteStack state)
{
- // We should never get here.
- Debug.Assert(false);
+ Debug.Fail("We should never get here.");
throw new InvalidOperationException();
}
JsonSerializerOptions options,
ref WriteStack state)
{
- // We should never get here.
- Debug.Assert(false);
+ Debug.Fail("We should never get here.");
throw new InvalidOperationException();
}
/// <summary>
/// Represents a strongly-typed property to prevent boxing and to create a direct delegate to the getter\setter.
/// </summary>
+ /// <typeparamref name="T"/> is the <see cref="JsonConverter{T}.TypeToConvert"/> for either the property's converter,
+ /// or a type's converter, if the current instance is a <see cref="JsonClassInfo.PropertyInfoForClassInfo"/>.
internal sealed class JsonPropertyInfo<T> : JsonPropertyInfo
{
public Func<object, T>? Get { get; private set; }
if (state.Current.ObjectState < StackFrameObjectState.ReadAheadNameOrEndObject)
{
// Read the first metadata property name.
- if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadNameOrEndObject))
+ if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadNameOrEndObject))
{
return false;
}
if (state.Current.ObjectState == StackFrameObjectState.ReadAheadRefValue)
{
- if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadRefValue))
+ if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadRefValue))
{
return false;
}
}
else if (state.Current.ObjectState == StackFrameObjectState.ReadAheadIdValue)
{
- if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadIdValue))
+ if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadIdValue))
{
return false;
}
if (state.Current.ObjectState == StackFrameObjectState.ReadAheadRefEndObject)
{
- if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadRefEndObject))
+ if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadRefEndObject))
{
return false;
}
if (state.Current.ObjectState == StackFrameObjectState.ReadAheadValuesName)
{
- if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadValuesName))
+ if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadValuesName))
{
return false;
}
if (state.Current.ObjectState == StackFrameObjectState.ReadAheadValuesStartArray)
{
- if (!ReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadValuesStartArray))
+ if (!TryReadAheadMetadataAndSetState(ref reader, ref state, StackFrameObjectState.ReadValuesStartArray))
{
return false;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- private static bool ReadAheadMetadataAndSetState(ref Utf8JsonReader reader, ref ReadStack state, StackFrameObjectState nextState)
+ private static bool TryReadAheadMetadataAndSetState(ref Utf8JsonReader reader, ref ReadStack state, StackFrameObjectState nextState)
{
+ // If we can't read here, the read will be completed at the root API by asking the stream for more data.
+ // Set the state so we know where to resume on re-entry.
state.Current.ObjectState = nextState;
return reader.Read();
}
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void Write_ConcurrentCollection()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void Read_ConcurrentCollection()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void ReadListOfList()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void WriteListOfList()
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Text.Json.Tests;
using Xunit;
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void ReadImmutableArrayOfImmutableArray()
using System.Collections.Generic;
using System.Collections.Immutable;
-using System.Text.Json.Tests;
using Xunit;
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void WriteImmutableArrayOfImmutableArray()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void ReadGenericIEnumerableOfIEnumerable()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void WriteIEnumerableOfIEnumerable()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void Read_ObjectModelCollection()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void Write_ObjectModelCollection()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void Read_SpecializedCollection()
namespace System.Text.Json.Serialization.Tests
{
- public static partial class ValueTests
+ public static partial class CollectionTests
{
[Fact]
public static void Write_SpecializedCollection()
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
-using System.Linq;
using Xunit;
namespace System.Text.Json.Serialization.Tests
// See the LICENSE file in the project root for more information.
using System.Globalization;
+using System.Runtime.CompilerServices;
using Xunit;
namespace System.Text.Json.Serialization.Tests