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

TypeHelper.IsMatch should check OriginalDefinition as well to work with generics #2132

Closed
andrei-epure-sonarsource opened this issue Nov 29, 2018 · 1 comment
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues.
Milestone

Comments

@andrei-epure-sonarsource
Copy link
Contributor

andrei-epure-sonarsource commented Nov 29, 2018

TypeHelper.IsMatch checks only the typeSymbol.

However, this won't work for generic collections for which the typeSymbol.SpecialType contains the concrete type - e.g. List<string>, whereas the generic type definition is List<T>.

To fix this, the OriginalDefinition.SpecialType should be compared as well, like below.

    return type.Matches(typeSymbol.SpecialType) ||
            type.Matches(typeSymbol.OriginalDefinition.SpecialType) ||
            type.Matches(typeSymbol.ToDisplayString()) ||
            type.Matches(typeSymbol.OriginalDefinition.ToDisplayString());
    }
@andrei-epure-sonarsource andrei-epure-sonarsource changed the title TypeHelper.IsMatch should check OriginalDefinition as well TypeHelper.IsMatch should check OriginalDefinition as well to work with generics Nov 29, 2018
@Evangelink Evangelink self-assigned this Dec 20, 2018
@Evangelink Evangelink added this to the 7.10 milestone Dec 20, 2018
@Evangelink Evangelink added Type: Improvement Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. labels Dec 20, 2018
@Evangelink
Copy link
Contributor

@andrei-epure-sonarsource The current approach that was taken, was to say that when calling this method, if you can have generics, then you should ensure the OriginalDefinition is passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues.
Projects
None yet
Development

No branches or pull requests

2 participants