-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Json
Milestone
Description
Background and motivation
There's already a GetTypeInfo method that takes a System.Type, but a really common case is to downcast to the generic version. This API makes it simple to perform the same operation without introducing potential errors.
API Proposal
namespace System.Text.Json;
public static class JsonSerializerOptionsExtensions
{
public static System.Text.Json.Serialization.Metadata.JsonTypeInfo<T> GetTypeInfo<T>(this JsonSerializerOptions options) { throw null; }
}API Usage
See, for example,
| var jsonTypeInfo = (JsonTypeInfo<T>)JsonSerializerOptions.Default.GetTypeInfo(typeof(T)); |
// Old use
var info = (JsonTypeInfo<string>)options.GetTypeInfo(typeof(string));
// New use
var info = options.GetTypeInfo<string>();Alternative Designs
No response
Risks
No response
martincostello, rabuckley, halter73 and IvanJosipovicRenderMichael, nil4, ArminShoeibi and AlgorithmsAreCool
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Text.Json