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

Suppress CA1725 for generic parameters #7077

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ private static void AnalyzeMethodSymbol(SymbolAnalysisContext analysisContext)
{
IParameterSymbol currentParameter = methodSymbol.Parameters[i];
IParameterSymbol bestMatchParameter = bestMatch.Parameters[i];
if (bestMatchParameter.OriginalDefinition.Type is ITypeParameterSymbol)
{
continue;
}

if (currentParameter.Name != bestMatchParameter.Name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,66 @@ End Sub
End Class");
}

[Fact]
public Task DontWarnWhenImplementingGenericParameterInInterface()
{
const string code = """
public interface IService<TEntity>
{
void Update(TEntity entity);
}

public class User {}

public class UserService : IService<User>
{
public void Update(User user) {}
}
""";

return VerifyCS.VerifyAnalyzerAsync(code);
}

[Fact]
public Task DontWarnWhenImplementingGenericParameterInBaseClass()
{
const string code = """
public class BaseService<TEntity>
{
public virtual void Update(TEntity entity) {}
}

public class User {}

public class UserService : BaseService<User>
{
public override void Update(User user) {}
}
""";

return VerifyCS.VerifyAnalyzerAsync(code);
}

[Fact]
public Task DontWarnWhenImplementingGenericParameterInAbstractBaseClass()
{
const string code = """
public abstract class BaseService<TEntity>
{
public abstract void Update(TEntity entity);
}

public class User {}

public class UserService : BaseService<User>
{
public override void Update(User user) {}
}
""";

return VerifyCS.VerifyAnalyzerAsync(code);
}

private static DiagnosticResult GetCSharpResultAt(int line, int column, string violatingMember, string violatingParameter, string baseParameter, string baseMember)
#pragma warning disable RS0030 // Do not use banned APIs
=> VerifyCS.Diagnostic()
Expand Down