Skip to content

Commit

Permalink
Release
Browse files Browse the repository at this point in the history
  • Loading branch information
egarim committed Sep 3, 2024
1 parent 0284dd6 commit a32e553
Show file tree
Hide file tree
Showing 6 changed files with 604 additions and 607 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ private static FieldInfo GetPrivateFieldWithPotentiallyTrimmedMetadata(this Type
{
public ParameterLookupKey(string name, Type type)
{
Name = name;
Type = type;
this.Name = name;
this.Type = type;
}

public string Name { get; }
public Type Type { get; }

public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(Name);
public bool Equals(ParameterLookupKey other) => Type == other.Type && string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase);
public override bool Equals(object? obj) => obj is ParameterLookupKey key && Equals(key);
public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(this.Name);
public bool Equals(ParameterLookupKey other) => this.Type == other.Type && string.Equals(this.Name, other.Name, StringComparison.OrdinalIgnoreCase);
public override bool Equals(object? obj) => obj is ParameterLookupKey key && this.Equals(key);
}

// Resolves the deserialization constructor for a type using logic copied from
Expand Down
58 changes: 29 additions & 29 deletions dotnet/src/InternalUtilities/src/Schema/JsonSchemaMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,42 +578,42 @@ private ref struct GenerationState

public GenerationState(JsonSchemaMapperConfiguration configuration)
{
_configuration = configuration;
_nullabilityInfoContext = configuration.ReferenceTypeNullability is ReferenceTypeNullability.Annotated ? new() : null;
_generatedTypePaths = configuration.AllowSchemaReferences ? new() : null;
_currentPath = configuration.AllowSchemaReferences ? new() : null;
_currentDepth = 0;
this._configuration = configuration;
this._nullabilityInfoContext = configuration.ReferenceTypeNullability is ReferenceTypeNullability.Annotated ? new() : null;
this._generatedTypePaths = configuration.AllowSchemaReferences ? new() : null;
this._currentPath = configuration.AllowSchemaReferences ? new() : null;
this._currentDepth = 0;
}

public readonly JsonSchemaMapperConfiguration Configuration => _configuration;
public readonly NullabilityInfoContext? NullabilityInfoContext => _nullabilityInfoContext;
public readonly int CurrentDepth => _currentDepth;
public readonly JsonSchemaMapperConfiguration Configuration => this._configuration;
public readonly NullabilityInfoContext? NullabilityInfoContext => this._nullabilityInfoContext;
public readonly int CurrentDepth => this._currentDepth;

public void Push(string nodeId)
{
if (_currentDepth == Configuration.MaxDepth)
if (this._currentDepth == this.Configuration.MaxDepth)
{
ThrowHelpers.ThrowInvalidOperationException_MaxDepthReached();
}

_currentDepth++;
this._currentDepth++;

if (Configuration.AllowSchemaReferences)
if (this.Configuration.AllowSchemaReferences)
{
Debug.Assert(_currentPath is not null);
_currentPath!.Add(nodeId);
Debug.Assert(this._currentPath is not null);
this._currentPath!.Add(nodeId);
}
}

public void Pop()
{
Debug.Assert(_currentDepth > 0);
_currentDepth--;
Debug.Assert(this._currentDepth > 0);
this._currentDepth--;

if (Configuration.AllowSchemaReferences)
if (this.Configuration.AllowSchemaReferences)
{
Debug.Assert(_currentPath is not null);
_currentPath!.RemoveAt(_currentPath.Count - 1);
Debug.Assert(this._currentPath is not null);
this._currentPath!.RemoveAt(this._currentPath.Count - 1);
}
}

Expand All @@ -622,13 +622,13 @@ public void Pop()
/// </summary>
public readonly void RegisterTypePath(Type type, Type? parentNullableOfT, JsonConverter? customConverter, bool isNullableReferenceType, JsonNumberHandling? customNumberHandling)
{
if (Configuration.AllowSchemaReferences)
if (this.Configuration.AllowSchemaReferences)
{
Debug.Assert(_currentPath is not null);
Debug.Assert(_generatedTypePaths is not null);
Debug.Assert(this._currentPath is not null);
Debug.Assert(this._generatedTypePaths is not null);

string pointer = _currentDepth == 0 ? "#" : "#/" + string.Join("/", _currentPath);
_generatedTypePaths!.Add((parentNullableOfT ?? type, customConverter, isNullableReferenceType, customNumberHandling), pointer);
string pointer = this._currentDepth == 0 ? "#" : "#/" + string.Join("/", this._currentPath);
this._generatedTypePaths!.Add((parentNullableOfT ?? type, customConverter, isNullableReferenceType, customNumberHandling), pointer);
}
}

Expand All @@ -637,10 +637,10 @@ public readonly void RegisterTypePath(Type type, Type? parentNullableOfT, JsonCo
/// </summary>
public readonly bool TryGetGeneratedSchemaPath(Type type, Type? parentNullableOfT, JsonConverter? customConverter, bool isNullableReferenceType, JsonNumberHandling? customNumberHandling, [NotNullWhen(true)] out string? value)
{
if (Configuration.AllowSchemaReferences)
if (this.Configuration.AllowSchemaReferences)
{
Debug.Assert(_generatedTypePaths is not null);
return _generatedTypePaths!.TryGetValue((parentNullableOfT ?? type, customConverter, isNullableReferenceType, customNumberHandling), out value);
Debug.Assert(this._generatedTypePaths is not null);
return this._generatedTypePaths!.TryGetValue((parentNullableOfT ?? type, customConverter, isNullableReferenceType, customNumberHandling), out value);
}

value = null;
Expand Down Expand Up @@ -810,9 +810,9 @@ private readonly struct SimpleTypeJsonSchema
{
public SimpleTypeJsonSchema(JsonSchemaType schemaType, string? format = null, string? pattern = null)
{
SchemaType = schemaType;
Format = format;
Pattern = pattern;
this.SchemaType = schemaType;
this.Format = format;
this.Pattern = pattern;
}

public JsonSchemaType SchemaType { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class JsonSchemaMapperConfiguration
/// </remarks>
public int MaxDepth
{
get => _maxDepth;
get => this._maxDepth;
init
{
if (value < 0)
Expand All @@ -87,7 +87,7 @@ public int MaxDepth
static void Throw() => throw new ArgumentOutOfRangeException(nameof(value));
}

_maxDepth = value;
this._maxDepth = value;
}
}
}
105 changes: 52 additions & 53 deletions dotnet/src/InternalUtilities/src/Schema/Polyfills/NullabilityInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,69 @@
#if !NET6_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;

namespace System.Reflection
namespace System.Reflection;

/// <summary>
/// A class that represents nullability info.
/// </summary>
[ExcludeFromCodeCoverage]
internal sealed class NullabilityInfo
{
/// <summary>
/// A class that represents nullability info.
/// </summary>
[ExcludeFromCodeCoverage]
internal sealed class NullabilityInfo
internal NullabilityInfo(Type type, NullabilityState readState, NullabilityState writeState,
NullabilityInfo? elementType, NullabilityInfo[] typeArguments)
{
internal NullabilityInfo(Type type, NullabilityState readState, NullabilityState writeState,
NullabilityInfo? elementType, NullabilityInfo[] typeArguments)
{
Type = type;
ReadState = readState;
WriteState = writeState;
ElementType = elementType;
GenericTypeArguments = typeArguments;
}
this.Type = type;
this.ReadState = readState;
this.WriteState = writeState;
this.ElementType = elementType;
this.GenericTypeArguments = typeArguments;
}

/// <summary>
/// The <see cref="System.Type" /> of the member or generic parameter
/// to which this NullabilityInfo belongs.
/// </summary>
public Type Type { get; }
/// <summary>
/// The <see cref="System.Type" /> of the member or generic parameter
/// to which this NullabilityInfo belongs.
/// </summary>
public Type Type { get; }

/// <summary>
/// The nullability read state of the member.
/// </summary>
public NullabilityState ReadState { get; internal set; }
/// <summary>
/// The nullability read state of the member.
/// </summary>
public NullabilityState ReadState { get; internal set; }

/// <summary>
/// The nullability write state of the member.
/// </summary>
public NullabilityState WriteState { get; internal set; }
/// <summary>
/// The nullability write state of the member.
/// </summary>
public NullabilityState WriteState { get; internal set; }

/// <summary>
/// If the member type is an array, gives the <see cref="NullabilityInfo" /> of the elements of the array, null otherwise.
/// </summary>
public NullabilityInfo? ElementType { get; }
/// <summary>
/// If the member type is an array, gives the <see cref="NullabilityInfo" /> of the elements of the array, null otherwise.
/// </summary>
public NullabilityInfo? ElementType { get; }

/// <summary>
/// If the member type is a generic type, gives the array of <see cref="NullabilityInfo" /> for each type parameter.
/// </summary>
public NullabilityInfo[] GenericTypeArguments { get; }
}
/// <summary>
/// If the member type is a generic type, gives the array of <see cref="NullabilityInfo" /> for each type parameter.
/// </summary>
public NullabilityInfo[] GenericTypeArguments { get; }
}

/// <summary>
/// An enum that represents nullability state.
/// </summary>
internal enum NullabilityState
{
/// <summary>
/// An enum that represents nullability state.
/// Nullability context not enabled (oblivious)
/// </summary>
internal enum NullabilityState
{
/// <summary>
/// Nullability context not enabled (oblivious)
/// </summary>
Unknown,
Unknown,

/// <summary>
/// Non nullable value or reference type
/// </summary>
NotNull,
/// <summary>
/// Non nullable value or reference type
/// </summary>
NotNull,

/// <summary>
/// Nullable value or reference type
/// </summary>
Nullable,
}
/// <summary>
/// Nullable value or reference type
/// </summary>
Nullable,
}
#endif
Loading

0 comments on commit a32e553

Please sign in to comment.