Skip to content

Commit

Permalink
Work around mono bug affecting Xamarin Android (#22982) (#22995)
Browse files Browse the repository at this point in the history
Fixes #22665

(cherry picked from commit fbc11f2)
  • Loading branch information
roji committed Oct 14, 2020
1 parent 15faabe commit 0980497
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/EFCore/Metadata/Conventions/NonNullableConventionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ protected virtual bool IsNonNullableReferenceType(
var state = GetOrInitializeState(modelBuilder);

// First check for [MaybeNull] on the return value. If it exists, the member is nullable.
// Note: avoid using GetCustomAttribute<> below because of https://github.com/mono/mono/issues/17477
var isMaybeNull = memberInfo switch
{
FieldInfo f => f.GetCustomAttribute<CA.MaybeNullAttribute>() != null,
PropertyInfo p => p.GetMethod?.ReturnParameter?.GetCustomAttribute<CA.MaybeNullAttribute>() != null,
FieldInfo f
=> f.CustomAttributes.Any(a => a.AttributeType == typeof(CA.MaybeNullAttribute)),
PropertyInfo p
=> p.GetMethod?.ReturnParameter?.CustomAttributes?.Any(a => a.AttributeType == typeof(CA.MaybeNullAttribute)) == true,
_ => false
};

Expand Down

0 comments on commit 0980497

Please sign in to comment.