提交 65092b44 编写于 作者: B Brian Freeman

update to include comment on both get and set routine

上级 cbd1d12c
......@@ -2361,7 +2361,7 @@ int Goo1
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
[WorkItem(42698, "https://github.com/dotnet/roslyn/issues/42698")]
public async Task TestRefactorRetainsComments()
public async Task TestMethodWithTrivia_3()
{
await TestInRegularAndScript1Async(
@"class C
......@@ -2376,6 +2376,37 @@ public async Task TestRefactorRetainsComments()
//Vital Comment
int FooBar => 1;
}");
}
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsReplaceMethodWithProperty)]
[WorkItem(42698, "https://github.com/dotnet/roslyn/issues/42698")]
public async Task TestMethodWithTrivia_4()
{
await TestWithAllCodeStyleOff(
@"class C
{
int [||]GetGoo() // Goo
{
}
void SetGoo(int i) // SetGoo
{
}
}",
@"class C
{
// Goo
// SetGoo
int Goo
{
get
{
}
set
{
}
}
}",
index: 1);
}
private async Task TestWithAllCodeStyleOff(
string initialMarkup, string expectedMarkup,
......
......@@ -49,12 +49,13 @@ private static bool OverridesMetadataSymbol(IMethodSymbol method)
var setMethodDeclaration = getAndSetMethods.SetMethodDeclaration;
var finalLeadingTrivia = getAndSetMethods.GetMethodDeclaration.GetLeadingTrivia().ToList();
if (getMethodDeclaration.ChildNodes().Any(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList && n.GetTrailingTrivia().Any(t => !syntaxFacts.IsWhitespaceOrEndOfLineTrivia(t))))
{
finalLeadingTrivia.AddRange(getMethodDeclaration.ChildNodes().Where(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList).First().GetTrailingTrivia());
}
if (setMethodDeclaration == null)
{
if (getMethodDeclaration.ChildNodes().Any(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList && n.GetTrailingTrivia().Any(t => !syntaxFacts.IsWhitespaceOrEndOfLineTrivia(t))))
{
finalLeadingTrivia.AddRange(getMethodDeclaration.ChildNodes().Where(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList).First().GetTrailingTrivia());
}
return property.WithLeadingTrivia(finalLeadingTrivia);
}
......@@ -62,6 +63,10 @@ private static bool OverridesMetadataSymbol(IMethodSymbol method)
setMethodDeclaration.GetLeadingTrivia()
.SkipWhile(t => syntaxFacts.IsEndOfLineTrivia(t))
.Where(t => !t.IsDirective));
if (setMethodDeclaration.ChildNodes().Any(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList && n.GetTrailingTrivia().Any(t => !syntaxFacts.IsWhitespaceOrEndOfLineTrivia(t))))
{
finalLeadingTrivia.AddRange(setMethodDeclaration.ChildNodes().Where(n => n.RawKind == syntaxFacts.SyntaxKinds.ParameterList).First().GetTrailingTrivia());
}
return property.WithLeadingTrivia(finalLeadingTrivia);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册