Skip to content
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

Refactor JsonPropertyInfo initialization infrastructure and implement JsonPropertyInfo.AttributeProvider #71514

Merged
merged 7 commits into from
Jul 4, 2022

Conversation

eiriktsarpalis
Copy link
Member

Makes the following changes:

  • Refactors JsonPropertyInfo initialization 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.
  • Simplify the converter resolution logic, removing dead branches and unnecessary parameterization.
  • Separate reflection-based JsonPropertyInfo metadata initialization into a separate method explicitly invoked by ReflectionJsonTypeInfo.
  • Apply consistent naming conventions e.g. renaming parentClassType to declaringType, ClrName to MemberName and memberType to typeToConvert. Remove unused parameters.
  • Implement JsonPropertyInfo.AttributeProvider and IsExtensionData properties as internal APIs.

Contributes to #63686.

@ghost
Copy link

ghost commented Jul 1, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Makes the following changes:

  • Refactors JsonPropertyInfo initialization 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.
  • Simplify the converter resolution logic, removing dead branches and unnecessary parameterization.
  • Separate reflection-based JsonPropertyInfo metadata initialization into a separate method explicitly invoked by ReflectionJsonTypeInfo.
  • Apply consistent naming conventions e.g. renaming parentClassType to declaringType, ClrName to MemberName and memberType to typeToConvert. Remove unused parameters.
  • Implement JsonPropertyInfo.AttributeProvider and IsExtensionData properties as internal APIs.

Contributes to #63686.

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Text.Json

Milestone: -

@@ -43,5 +43,24 @@ public static bool IsAssignableFromInternal(this Type type, Type from)

private static bool HasJsonConstructorAttribute(ConstructorInfo constructorInfo)
=> constructorInfo.GetCustomAttribute<JsonConstructorAttribute>() != null;

public static TAttribute? GetUniqueCustomAttribute<TAttribute>(this MemberInfo memberInfo, bool inherit)
Copy link
Member

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

DeclaringType = declaringType;
PropertyType = propertyType;
Options = options;
ParentTypeInfo = parentTypeInfo; // null parentTypeInfo means it's not tied yet
Copy link
Member

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?

Copy link
Member Author

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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider: propertyType

Copy link
Member

@krwq krwq left a 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

@eiriktsarpalis eiriktsarpalis merged commit 32d0360 into dotnet:main Jul 4, 2022
@eiriktsarpalis eiriktsarpalis deleted the jsonextensiondata branch July 4, 2022 11:43
@ghost ghost locked as resolved and limited conversation to collaborators Aug 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants