Skip to content

Commit

Permalink
Replace our nullability decoding with the new BCL API (#2156)
Browse files Browse the repository at this point in the history
Closes #2155
  • Loading branch information
roji authored Dec 16, 2021
1 parent cf4f23e commit 1d313b3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 145 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.PG/EFCore.PG.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</ItemGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="\"/>
<None Include="README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
21 changes: 16 additions & 5 deletions src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Numerics;
using System.Text;
using System.Text.Json;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal;
using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping;
using Npgsql.EntityFrameworkCore.PostgreSQL.Utilities;
Expand All @@ -32,7 +33,7 @@ static NpgsqlTypeMappingSource()
}

private readonly ISqlGenerationHelper _sqlGenerationHelper;
private readonly ReferenceNullabilityDecoder _referenceNullabilityDecoder = new();
private readonly NullabilityInfoContext _nullabilityInfoContext = new();

protected virtual ConcurrentDictionary<string, RelationalTypeMapping[]> StoreTypeMappings { get; }
protected virtual ConcurrentDictionary<Type, RelationalTypeMapping> ClrTypeMappings { get; }
Expand Down Expand Up @@ -827,11 +828,21 @@ private static bool NameBasesUsesPrecision(ReadOnlySpan<char> span)
// We decode NRT annotations here to return the correct type mapping.
if (mapping is NpgsqlArrayTypeMapping arrayMapping
&& !arrayMapping.ElementMapping.ClrType.IsValueType
&& !property.IsShadowProperty()
&& property.GetMemberInfo(forMaterialization: false, forSet: false) is { } memberInfo
&& memberInfo.GetMemberType().IsArrayOrGenericList())
&& !property.IsShadowProperty())
{
if (_referenceNullabilityDecoder.IsArrayOrListElementNonNullable(memberInfo))
var nullabilityInfo =
property.PropertyInfo is { } propertyInfo
? _nullabilityInfoContext.Create(propertyInfo)
: property.FieldInfo is { } fieldInfo
? _nullabilityInfoContext.Create(fieldInfo)
: null;

// We already know from the mapping check above that the member is either an array or a generic list
var elementNullabilityInfo = nullabilityInfo?.ElementType
?? (nullabilityInfo?.GenericTypeArguments.Length > 0 ? nullabilityInfo.GenericTypeArguments[0] : null);

if (elementNullabilityInfo?.ReadState == NullabilityState.NotNull
&& elementNullabilityInfo.WriteState == NullabilityState.NotNull)
{
return arrayMapping.MakeNonNullable();
}
Expand Down
139 changes: 0 additions & 139 deletions src/EFCore.PG/Utilities/ReferenceNullabilityDecoder.cs

This file was deleted.

0 comments on commit 1d313b3

Please sign in to comment.