Skip to content

Commit

Permalink
Don't report CA2257 on nested types
Browse files Browse the repository at this point in the history
Fixes #7106
  • Loading branch information
jkoritzinsky committed Jan 23, 2024
1 parent abef8ce commit 4949055
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ private static void AnalyzeType(SymbolAnalysisContext context, INamedTypeSymbol

foreach (var member in targetType.GetMembers())
{
if (!member.IsImplementationOfAnyExplicitInterfaceMember() && !member.IsStatic)
if (!member.IsImplementationOfAnyExplicitInterfaceMember() && !member.IsStatic && !member.IsType())
{
// We don't want to emit diagnostics when the member is an accessor method.
if (member is not IMethodSymbol { AssociatedSymbol: IPropertySymbol or IEventSymbol })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,31 @@ static void I.M()
await VerifyCSCodeFixAsync(source, fixedSource, CSharp.LanguageVersion.Preview, ReferenceAssemblies.Net.Net60);
}

[Fact]
[WorkItem(7106, "htpts://github.com/dotnet/roslyn-analyzers/issues/7106")]
public async Task DynamicInterfaceCastableImplementation_NonStatic_NestedType()
{
string source = @"
using System.Runtime.InteropServices;
public interface IMyInterface
{
void M();
}
[DynamicInterfaceCastableImplementation]
internal interface IImpl : IMyInterface
{
internal class C { }
void IMyInterface.M()
{
}
}
";
await VerifyCSAnalyzerAsync(source);
}

private static Task VerifyCSAnalyzerAsync(string source)
{
return VerifyCSCodeFixAsync(source, source);
Expand Down

0 comments on commit 4949055

Please sign in to comment.