예제 #1
0
		public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node)
		{
			var visibilityTokens = node.DescendantTokens(_ => true)
				.Where(_ => _.IsKind(SyntaxKind.PublicKeyword) ||
					_.IsKind(SyntaxKind.PrivateKeyword) ||
					_.IsKind(SyntaxKind.ProtectedKeyword) ||
					_.IsKind(SyntaxKind.InternalKeyword)).ToImmutableList();

			if (!visibilityTokens.Any(_ => _.IsKind(SyntaxKind.PublicKeyword)))
			{
				var tokenPosition = 0;

				var newMethod = node.ReplaceTokens(visibilityTokens,
					(_, __) =>
					{
						tokenPosition++;

						return tokenPosition == 1 ?
							SyntaxFactory.Token(
								_.LeadingTrivia,
								SyntaxKind.PublicKeyword,
								_.TrailingTrivia) :
							new SyntaxToken();
					});
				return newMethod;
			}
			else
			{
				return node;
			}
		}
 private static bool IsAsync(MethodDeclarationSyntax methodDeclarationSyntax)
 {
     return methodDeclarationSyntax.DescendantTokens().Any(x => x.ValueText == "async");
 }