Skip to content
This repository was archived by the owner on Jul 12, 2022. It is now read-only.

Commit b034839

Browse files
committed
Do not add modifiers to partial methods
Partial methods cannot have explicit modifiers, they are implicitly private. closes #46
1 parent 3c16dd4 commit b034839

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Microsoft.DotNet.CodeFormatting.Tests/Rules/ExplicitVisibilityRuleTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,28 @@ private class N2 { }
360360
}
361361
362362
public partial class C { }
363+
";
364+
365+
Verify(text, expected, runFormatter: false);
366+
}
367+
368+
[Fact]
369+
public void IgnorePartialMethods()
370+
{
371+
var text = @"
372+
class C
373+
{
374+
void M1();
375+
partial void M2();
376+
}
377+
";
378+
379+
var expected = @"
380+
internal class C
381+
{
382+
private void M1();
383+
partial void M2();
384+
}
363385
";
364386

365387
Verify(text, expected, runFormatter: false);

src/Microsoft.DotNet.CodeFormatting/Rules/ExplicitVisibilityRule.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public override SyntaxNode VisitConstructorDeclaration(ConstructorDeclarationSyn
6868

6969
public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)
7070
{
71-
if (node.ExplicitInterfaceSpecifier != null)
71+
if (node.ExplicitInterfaceSpecifier != null || node.Modifiers.Any(x => x.IsKind(SyntaxKind.PartialKeyword)))
7272
{
7373
return node;
7474
}

0 commit comments

Comments
 (0)