-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Expose ElementType and KeyType on JsonTypeInfo metadata. #77306
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue Detailspublic class partial JsonTypeInfo
{
public Type KeyType { get; } // relevant for JsonTypeInfoKind.Dictionary
public Type ElementType { get; } // relevant for JsonTypeInfoKind.Enumerable/Dictionary
} These APIs are useful for querying the model, i.e.: generating docs, schema. It's not exactly trivial to implement them but we already store this data internally. cc: @captainsafia
|
consider how this interacts with custom element converters and element polymorphic serialization |
Should these be nullable? |
@captainsafia is this blocking you for .NET 8? We're moving it to Future if not. |
@eiriktsarpalis It's no longer blocking for .NET 8 so it's sufficient to move it back to Future. |
Looks good as proposed. public partial class JsonTypeInfo
{
public Type? KeyType { get; } // relevant for JsonTypeInfoKind.Dictionary
public Type? ElementType { get; } // relevant for JsonTypeInfoKind.Enumerable/Dictionary
} |
I don't have much knowledge about this area, but I wanted to ask anyway: shouldn't those properties return |
Also, given the previous API review about Maybe the same argument applies here as well, because people will check whether the |
No. The simple reason is that resolving the
The current behavior is consistent with the other public APIs on JsonTypeInfo. We only throw in property setters where the kind doesn't match. |
If it's locally consistent, then I understand. Although now I'm confused when you said:
Isn't this the same thing? The property would throw if the kind doesn't match (disregarding the fact that properties shouldn't throw at all, and if it needs to, it should be a method instead. But you said there's prior art for this). |
There are no setters in the new properties. |
These APIs are useful for querying the model, i.e.: generating docs, schema. It's not exactly trivial to implement them but we already store this data internally.
cc: @captainsafia
The text was updated successfully, but these errors were encountered: