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

When a type implements interface explicitly, then CA1859 gives false positive when th explicit implementation is used through the interface type. #7558

Open
bharathkolanda opened this issue Feb 3, 2025 · 1 comment

Comments

@bharathkolanda
Copy link

Analyzer

Diagnostic ID: CA1859: Use concrete types when possible for improved performance

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: SDK 8.0.101

Describe the bug

CA1859 is falsely raised when a type implements an interface explicitly. Applying the suggested fix leads to compilation errors.

Steps To Reproduce

interface IFoo
{
bool Attach(IContext context);
}

class SampleHandler : IFoo
{
bool IFoo.Attach(IContext context)
{
....
return true;
}
}

IFoo fooClone = new SampleHandler();
Change type of variable 'fooClone' from 'IFoo' to 'SampleHandler' for improved performance
bool attachResult = fooClone.Attach( workingContext );

Expected behavior

Actual behavior

CA1859 is raised for fooClone.Attach method, suggesting to change the type to SampleHandler.

@YoshiRulz
Copy link

I think that's correct? If the implementation in SampleHandler was new then it shouldn't be flagged.

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

2 participants