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 implementing multiple IConverter<,> in single converter class #8881
Open
ccorsano
wants to merge
4
commits into
dotnet:main
Choose a base branch
from
ccorsano:multiple_surrogate_in_converter
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ReubenBond
reviewed
Feb 25, 2024
@@ -570,7 +570,8 @@ private bool TryGetSurrogateCodec(Type fieldType, Type searchType, out Type surr | |||
var converterInterfaceArgs = Array.Empty<Type>(); | |||
foreach (var @interface in converterType.GetInterfaces()) | |||
{ | |||
if (@interface.IsConstructedGenericType && @interface.GetGenericTypeDefinition() == typeof(IConverter<,>)) | |||
if (@interface.IsConstructedGenericType && @interface.GetGenericTypeDefinition() == typeof(IConverter<,>) | |||
&& @interface.GenericTypeArguments[0].IsAssignableFrom(fieldType)) |
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 this be an equality check instead?
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.
Yes a simpler equality check should be fine.
ccorsano
force-pushed
the
multiple_surrogate_in_converter
branch
from
March 7, 2024 19:35
3fd4ac4
to
ec56684
Compare
ReubenBond
approved these changes
Mar 7, 2024
Should we also add |
- When declaring a single converter class for multiple surrogates, ICopier will always resolve the last declared IConverter<,> interface, failing with a InvalidCastException at runtime
- Added Equals and GetHashCode to foreign types
- Only resolves IConverter<,> interface matching foreign type
ReubenBond
force-pushed
the
multiple_surrogate_in_converter
branch
from
March 7, 2024 22:05
ec56684
to
778cb54
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix and unit test for #8879
Only select IConverter<,> interfaces whose types arguments matches the searched type.
Unit test also submitted separately as a fail test in #8880
Microsoft Reviewers: Open in CodeFlow