-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[System.Text.Json] Expose additional metadata in contract APIs. #102078
Labels
api-approved
API was approved in API review, it can be implemented
area-System.Text.Json
blocking
Marks issues that we want to fast track in order to unblock other important work
Milestone
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection |
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
9 tasks
namespace System.Text.Json.Serialization.Metadata;
public partial class JsonTypeInfo
{
// Attribute provider for the deserialization constructor (aka `JsonConstructorAttribute` ctors)
public ICustomAttributeProvider? ConstructorAttributeProvider { get; }
}
public partial class JsonPropertyInfo
{
public Type DeclaringType { get; }
// The JsonParameterInfo that has been associated with the current property.
public JsonParameterInfo? AssociatedParameter { get; }
// Existing
// public ICustomAttributeProvider? AttributeProvider { get; set; }
}
// Currently internal type, exposed as a read-only façade for now.
public sealed class JsonParameterInfo
{
public Type DeclaringType { get; }
public int Position { get; }
public Type ParameterType { get; }
public bool HasDefaultValue { get; }
public object? DefaultValue { get; }
public bool DisallowNull { get; }
public ICustomAttributeProvider? AttributeProvider { get; }
}
// New APIs for SG-specific APIs
public partial class JsonObjectInfoValues<T>
{
public Func<ICustomAttributeProvider?>? ConstructorAttributeProviderFactory { get; init; }
}
public partial class JsonPropertyInfoValues<T>
{
public Func<ICustomAttributeProvider?>? AttributeProviderFactory { get; init; }
}
public partial class JsonParameterInfoValues
{
public bool DisallowNull { get; init; }
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
api-approved
API was approved in API review, it can be implemented
area-System.Text.Json
blocking
Marks issues that we want to fast track in order to unblock other important work
Background and motivation
Contributes to #100159. The implementation of the https://github.com/eiriktsarpalis/stj-schema-mapper prototype revealed a number of gaps in the existing STJ contract metadata APIs which currently need to be filled manually using reflection or need to be extracted from private fields in the STJ implementation itself.
This proposal includes all the APIs necessary to make schema-related metadata available to end-users looking to export STJ schemas for .NET types, both for reflection and the source generator. The primary motivation is giving access to attribute metadata, via the
ICustomAttributeProvider
abstraction in a way that works well for both reflection and source generators/trimmed apps without compromising startup time or application size.API Proposal
API Usage
Consider the user defined-type:
Then the source generator would be able to give access to property attributes by generating the following code:
Factoring the attribute provider resolution logic into a delegate that uses a reflection literal expression this ensures that
cc @jozkee @stephentoub @eerhardt @captainsafia
The text was updated successfully, but these errors were encountered: