Skip to content

Commit ef223ab

Browse files
committed
Another approach
1 parent 7cd2b05 commit ef223ab

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1648InheritDocMustBeUsedWithInheritingClass.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,28 @@ private static void HandleMemberDeclaration(SyntaxNodeAnalysisContext context)
159159
}
160160
}
161161

162-
// "class Test {}" has assigne System.Object as its base type.
163-
if (memberSyntax is ConstructorDeclarationSyntax && declaredSymbol is IMethodSymbol methodSymbol && methodSymbol.ContainingType != null
164-
&& methodSymbol.ContainingType.BaseType?.SpecialType != SpecialType.System_Object)
162+
if (memberSyntax is ConstructorDeclarationSyntax constructorDeclarationSyntax)
165163
{
166-
return;
164+
// ConstructorInitializerSyntax initializer = constructorDeclarationSyntax.Initializer;
165+
ISymbol symbol = context.SemanticModel.GetDeclaredSymbol(constructorDeclarationSyntax, context.CancellationToken);
166+
167+
if (symbol is IMethodSymbol constructorMethodSymbol && constructorMethodSymbol.ContainingType is INamedTypeSymbol enclosingNamedTypeSymbol)
168+
{
169+
INamedTypeSymbol baseType = enclosingNamedTypeSymbol.BaseType;
170+
171+
if (baseType.SpecialType != SpecialType.System_Object)
172+
{
173+
foreach (IMethodSymbol baseConstructorMethod in baseType.Constructors)
174+
{
175+
// TODO: SymbolEqualityComparer?
176+
if (constructorMethodSymbol.Parameters.SequenceEqual(baseConstructorMethod.Parameters))
177+
{
178+
// Matching constructor was found.
179+
return;
180+
}
181+
}
182+
}
183+
}
167184
}
168185

169186
if (documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) is XmlEmptyElementSyntax includeElement)

0 commit comments

Comments
 (0)