Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NativeAOT warnings on comparers. #35559

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/EFCore/ChangeTracking/GeometryValueComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
/// <remarks>
/// See <see href="https://aka.ms/efcore-docs-value-comparers">EF Core value comparers</see> for more information and examples.
/// </remarks>
public class GeometryValueComparer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] TGeometry>
public class GeometryValueComparer
<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
TGeometry>
: ValueComparer<TGeometry>
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;

using System.Diagnostics.CodeAnalysis;
using static Expression;

/// <summary>
Expand All @@ -15,7 +16,11 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </remarks>
public class ConvertingValueComparer<TTo, TFrom> : ValueComparer<TTo>, IInfrastructure<ValueComparer>
public class ConvertingValueComparer
<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
TTo, TFrom> : ValueComparer<TTo>, IInfrastructure<ValueComparer>
{
private readonly ValueComparer<TFrom> _valueComparer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;

/// <summary>
Expand All @@ -9,7 +11,11 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class NullableValueComparer<T> : ValueComparer<T?>, IInfrastructure<ValueComparer>
public class NullableValueComparer
<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
T> : ValueComparer<T?>, IInfrastructure<ValueComparer>
where T : struct
{
private static readonly PropertyInfo _hasValueProperty = typeof(T?).GetProperty("HasValue")!;
Expand Down
13 changes: 10 additions & 3 deletions src/EFCore/ChangeTracking/ValueComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ public static HashCode Add(HashCode hash, int code)
public static ValueComparer CreateDefault(
[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.NonPublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
Type type,
bool favorStructuralComparisons)
Expand All @@ -279,7 +278,11 @@ public static ValueComparer CreateDefault(
/// </param>
/// <typeparam name="T">The type.</typeparam>
/// <returns>The <see cref="ValueComparer{T}" />.</returns>
public static ValueComparer CreateDefault<T>(bool favorStructuralComparisons)
public static ValueComparer CreateDefault
<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
T>(bool favorStructuralComparisons)
{
var nonNullableType = typeof(T).UnwrapNullableType();

Expand Down Expand Up @@ -313,7 +316,11 @@ public static ValueComparer CreateDefault<T>(bool favorStructuralComparisons)
}

// PublicMethods is required to preserve e.g. GetHashCode
internal class DefaultValueComparer<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] T> : ValueComparer<T>
internal class DefaultValueComparer
<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
T> : ValueComparer<T>
{
public DefaultValueComparer(bool favorStructuralComparisons)
: base(favorStructuralComparisons)
Expand Down
6 changes: 2 additions & 4 deletions src/EFCore/ChangeTracking/ValueComparer`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,10 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
/// <typeparam name="T">The type.</typeparam>
// PublicMethods is required to preserve e.g. GetHashCode
public class ValueComparer
<[DynamicallyAccessedMembers(
<[DynamicallyAccessedMembers(
DynamicallyAccessedMemberTypes.PublicMethods
| DynamicallyAccessedMemberTypes.NonPublicMethods
| DynamicallyAccessedMemberTypes.PublicProperties)]
T>
: ValueComparer, IEqualityComparer<T>
T> : ValueComparer, IEqualityComparer<T>
{
private Func<T?, T?, bool>? _equals;
private Func<T, int>? _hashCode;
Expand Down