dotnet/runtime

Support using any dictionary as JsonExtensionData

Open

#31,645 opened on Feb 3, 2020

View on GitHub
 (23 comments) (8 reactions) (1 assignee)C# (5,445 forks)batch import
area-System.Text.Jsonenhancementhelp wantedwishlist

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (Avg merge 12d 11h) (661 merged PRs in 30d)

Description

IMHO, IReadOnlyDictionary should work identical to IDictionary when using with JsonExtensionData attribute.

[JsonExtensionData]
public IReadOnlyDictionary<string, JsonElement> Payload { get; set; }

Currently it fails with error:

System.InvalidOperationException: The data extension property 'Payload' does not match the required signature of IDictionary<string, JsonElement> or IDictionary<string, object>.

This is analogous to collection properties which can be defined as List<T>, IList<T> or IReadOnlyList<T> etc.

Contributor guide