diff --git a/src/Features/Core/Portable/ReplaceMethodWithProperty/AbstractReplaceMethodWithPropertyService.cs b/src/Features/Core/Portable/ReplaceMethodWithProperty/AbstractReplaceMethodWithPropertyService.cs index 46104ebea71da89554047ef852c03c8bd0d13a21..1db3cfb48d2b29720de0938de8c49bf82027d6f8 100644 --- a/src/Features/Core/Portable/ReplaceMethodWithProperty/AbstractReplaceMethodWithPropertyService.cs +++ b/src/Features/Core/Portable/ReplaceMethodWithProperty/AbstractReplaceMethodWithPropertyService.cs @@ -48,14 +48,15 @@ private static bool OverridesMetadataSymbol(IMethodSymbol method) var getMethodDeclaration = getAndSetMethods.GetMethodDeclaration; var setMethodDeclaration = getAndSetMethods.SetMethodDeclaration; var finalLeadingTrivia = getAndSetMethods.GetMethodDeclaration.GetLeadingTrivia().ToList(); + var paramList = syntaxFacts.GetParameterList(getMethodDeclaration); //If there is a comment on the same line as the method it is contained in trailing trivia for the parameter list //If it's there we need to add it to the final comments //this is to fix issue 42699, https://github.com/dotnet/roslyn/issues/42699 - if (getMethodDeclaration.ChildNodes().Any(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList && n.GetTrailingTrivia().Any(t => !syntaxFacts.IsWhitespaceOrEndOfLineTrivia(t)))) + if (paramList.GetTrailingTrivia().Any(t => !syntaxFacts.IsWhitespaceOrEndOfLineTrivia(t))) { //we have a meaningful comment on the parameter list so add it to the trivia list - finalLeadingTrivia.AddRange(getMethodDeclaration.ChildNodes().Where(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList).First().GetTrailingTrivia()); + finalLeadingTrivia.AddRange(paramList.GetTrailingTrivia()); } if (setMethodDeclaration == null) @@ -70,10 +71,11 @@ private static bool OverridesMetadataSymbol(IMethodSymbol method) //If there is a comment on the same line as the method it is contained in trailing trivia for the parameter list //If it's there we need to add it to the final comments - if (setMethodDeclaration.ChildNodes().Any(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList && n.GetTrailingTrivia().Any(t => !syntaxFacts.IsWhitespaceOrEndOfLineTrivia(t)))) + paramList = syntaxFacts.GetParameterList(setMethodDeclaration); + if (paramList.GetTrailingTrivia().Any(t => !syntaxFacts.IsWhitespaceOrEndOfLineTrivia(t))) { //we have a meaningful comment on the parameter list so add it to the trivia list - finalLeadingTrivia.AddRange(setMethodDeclaration.ChildNodes().Where(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList).First().GetTrailingTrivia()); + finalLeadingTrivia.AddRange(paramList.GetTrailingTrivia()); } return property.WithLeadingTrivia(finalLeadingTrivia);