dotnet/runtime

Support using any dictionary as JsonExtensionData

Open

#31.645 aperta il 3 feb 2020

Vedi su GitHub
 (23 commenti) (8 reazioni) (1 assegnatario)C# (5445 fork)batch import
area-System.Text.Jsonenhancementhelp wantedwishlist

Metriche repository

Star
 (17.886 star)
Metriche merge PR
 (Merge medio 12g 11h) (661 PR mergiate in 30 g)

Descrizione

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.

Guida contributor