-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support for classes with duplicate names #30
Comments
Perhaps it makes sense to add the ability to define a custom resolver like |
like this internal static void AddAutoDiscriminators(this DiscriminatorValues discriminatorValues, Type[] inherited)
{
foreach (var type in inherited)
{
if (discriminatorValues.Contains(type))
continue;
discriminatorValues.AddType(type, resolver(type)); }
}
resolver = x => x.FullName; |
@RonSijm Then the general behavior will not change, but you can redefine what you need |
Do you want to do that? |
Sure, a I have a working prototype locally, but I'm not sure about the implementation. I tried multiple different things, like I've added a The problem with that was that it changes the settings project-wide. Ideally it should be possible to set this name resolver in an attribute or something - but it doesn't seem very possible to do so. I have an implementation that works with multiple different types - I'll try to create a PR for it |
I've created a PR with the implementation I was using: #31
I've added a test to show it works |
Hi there, I've used your library, and it seems to work in most of the cases, unless there are classes with duplicate names. I've created two test scenarios:
Scenario 1: Duplicate classes in a different namespace
Scenario 2: Nested classes:
Both cases fail in
DiscriminatorValuesManager.AddAutoDiscriminators
with the exception: JsonKnownTypes.Exceptions.JsonKnownTypesException: 'ClassInContainer discriminator already in use'I suppose one solution would be to add a
JsonDiscriminatorAttribute
on all the classes, But in case of the second scenario, it is a common pattern in MediatR that every inner class is either called Query or Command - so I'd have to add an attribute to every single class.A simple solution seems to be to simply have longer type descriptors:
though of course this is a big breaking change for everyone...
I was wondering if there's a better approach to this - besides downloading this package from source and modifying the type descriptor code
The text was updated successfully, but these errors were encountered: