-
Notifications
You must be signed in to change notification settings - Fork 512
Allow inheritdoc for class constructors with base types #3719
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
Changes from 4 commits
2d5a62f
7cd2b05
ef223ab
d58dede
836540c
62237f3
49d59ce
b7d10a8
fd402ad
5ecef98
31643cf
50a5fbf
3ca55e3
182e0a7
0ebb990
7183ec0
db794b0
858e7a1
80804ab
3800377
6e752bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,56 @@ private static void HandleMemberDeclaration(SyntaxNodeAnalysisContext context) | |
} | ||
} | ||
|
||
if (memberSyntax is ConstructorDeclarationSyntax constructorDeclarationSyntax) | ||
{ | ||
ISymbol symbol = context.SemanticModel.GetDeclaredSymbol(constructorDeclarationSyntax, context.CancellationToken); | ||
MartyIX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (symbol is IMethodSymbol constructorMethodSymbol && constructorMethodSymbol.ContainingType is INamedTypeSymbol enclosingNamedTypeSymbol) | ||
MartyIX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
INamedTypeSymbol baseType = enclosingNamedTypeSymbol.BaseType; | ||
|
||
if (baseType.SpecialType != SpecialType.System_Object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really want it to trigger for this case? Maybe not the best documentation, but the use of What do you think, @sharwell? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added support for this case to follow the VS approach. |
||
{ | ||
bool foundMatchingConstructorsToInheritFrom = false; | ||
|
||
foreach (IMethodSymbol baseConstructorMethod in baseType.Constructors) | ||
{ | ||
// Constructors must have the same number of parameters. | ||
if (constructorMethodSymbol.Parameters.Count() != baseConstructorMethod.Parameters.Count()) | ||
{ | ||
continue; | ||
} | ||
|
||
// Our constructor and the base constructor must have the same signature. But variable names can be different. | ||
bool success = true; | ||
|
||
for (int i = 0; i < constructorMethodSymbol.Parameters.Length; i++) | ||
{ | ||
IParameterSymbol constructorParameter = constructorMethodSymbol.Parameters[i]; | ||
IParameterSymbol baseParameter = baseConstructorMethod.Parameters[i]; | ||
|
||
if (!constructorParameter.Type.Equals(baseParameter.Type)) | ||
{ | ||
success = false; | ||
break; | ||
} | ||
} | ||
|
||
if (success) | ||
{ | ||
foundMatchingConstructorsToInheritFrom = true; | ||
break; | ||
} | ||
} | ||
|
||
if (foundMatchingConstructorsToInheritFrom) | ||
{ | ||
return; | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (documentation.Content.GetFirstXmlElement(XmlCommentHelper.IncludeXmlTag) is XmlEmptyElementSyntax includeElement) | ||
{ | ||
if (declaredSymbol == null) | ||
|
Uh oh!
There was an error while loading. Please reload this page.