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

Method Resolution Conflict in SystemTextJsonReflectionService #1715

Open
BlackGad opened this issue Jul 5, 2024 · 0 comments
Open

Method Resolution Conflict in SystemTextJsonReflectionService #1715

BlackGad opened this issue Jul 5, 2024 · 0 comments

Comments

@BlackGad
Copy link

BlackGad commented Jul 5, 2024

Description:
In the SystemTextJsonReflectionService class, there are two methods named GetPropertyName with different signatures. The GenerateProperties method calls GetPropertyName, but the compiler resolves this call to the private static method, not the public override method. This makes it impossible to override the GetPropertyName method in a custom ReflectionServiceBase.

Steps to Reproduce:

  1. Create a custom ReflectionServiceBase class.
  2. Override the GetPropertyName method.
  3. Observe that the overridden method is not called in the GenerateProperties method.

Expected Behavior:
The call to GetPropertyName in the GenerateProperties method should resolve to the public override method, allowing it to be overridden in a derived class.

Proposed Solution:
Rename the static method to GetStaticPropertyName or modify its signature to avoid the conflict.

Code Example:

public override string GetPropertyName(ContextualAccessorInfo accessorInfo, JsonSchemaGeneratorSettings settings);
private static string GetPropertyName(ContextualAccessorInfo accessorInfo, SystemTextJsonSchemaGeneratorSettings settings);

public void GenerateProperties(...)
{
    var propertyTypeDescription = GetDescription(accessorInfo.AccessorType, settings.DefaultReferenceTypeNullHandling, settings);
    var propertyName = GetPropertyName(accessorInfo, settings); // This resolves to the static method
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant