Skip to content

Commit

Permalink
Metadata: Disallow backing field on indexer property
Browse files Browse the repository at this point in the history
- Don't discover backing field for indexer property by convention
- Throw if trying to set a backing field for indexer property

Resolves #19448
  • Loading branch information
smitpatel committed Jan 1, 2020
1 parent a8072e9 commit 64b8b40
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/EFCore/Metadata/Internal/PropertyBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public virtual void SetField([CanBeNull] FieldInfo fieldInfo, ConfigurationSourc
return;
}

if (PropertyInfo != null
&& PropertyInfo.IsIndexerProperty()
&& fieldInfo != null)
{
throw new InvalidOperationException(
CoreStrings.BackingFieldOnIndexer(fieldInfo.GetSimpleMemberName(), DeclaringType.DisplayName(), Name));
}

if (fieldInfo != null)
{
IsCompatible(fieldInfo, ClrType, DeclaringType.ClrType, Name, shouldThrow: true);
Expand Down

0 comments on commit 64b8b40

Please sign in to comment.