-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Refactor JsonPropertyInfo initialization infrastructure and implement JsonPropertyInfo.AttributeProvider #71514
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
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsMakes the following changes:
Contributes to #63686.
|
...ibraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs
Outdated
Show resolved
Hide resolved
...ibraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfoOfT.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonTypeInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverter.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs
Outdated
Show resolved
Hide resolved
…ion infrastructure
…ion/Metadata/JsonPropertyInfo.cs
…ion/Metadata/JsonPropertyInfo.cs
dd907ca to
c9cb9bd
Compare
| private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo) | ||
| => constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null; | ||
|
|
||
| public static TAttribute? GetUniqueCustomAttribute<TAttribute>(this MemberInfo memberInfo, bool inherit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: consider ICustomAttributeProvider rather than MemberInfo
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/JsonConverterOfT.cs
Show resolved
Hide resolved
...raries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/CustomJsonTypeInfoOfT.cs
Show resolved
Hide resolved
src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Metadata/JsonPropertyInfo.cs
Show resolved
Hide resolved
| DeclaringType = declaringType; | ||
| PropertyType = propertyType; | ||
| Options = options; | ||
| ParentTypeInfo = parentTypeInfo; // null parentTypeInfo means it's not tied yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we debug assert that if parentTypeInfo is not null then declaringType == parentTypeInfo.Type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, I'll add in the next round of PRs
| } | ||
|
|
||
| private JsonPropertyInfo? AddProperty( | ||
| Type typeToConvert, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider: propertyType
krwq
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with couple of suggestions
Makes the following changes:
JsonPropertyInfoinitialization so that a minimal subset of required parameters are read-only and settable via constructors instead of property setters. Simplify initialization logic removing dead branches and unnecessary parameterization.JsonPropertyInfometadata initialization into a separate method explicitly invoked by ReflectionJsonTypeInfo.parentClassTypetodeclaringType,ClrNametoMemberNameandmemberTypetotypeToConvert. Remove unused parameters.JsonPropertyInfo.AttributeProviderandIsExtensionDataproperties as internal APIs.Contributes to #63686.