private async Task<Document> DiagnosticSeverityError(Document document, ArgumentSyntax argument, CancellationToken c) { SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document); SyntaxNode expression = generator.IdentifierName("DiagnosticSeverity"); var newExpression = generator.MemberAccessExpression(expression, "Error") as ExpressionSyntax; var rule = argument.FirstAncestorOrSelf<FieldDeclarationSyntax>(); var newRule = rule.ReplaceNode(argument.Expression, newExpression); return await ReplaceNode(argument.FirstAncestorOrSelf<FieldDeclarationSyntax>(), newRule.WithTrailingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.EndOfLine("\r\n"), SyntaxFactory.Whitespace(" "), SyntaxFactory.ParseTrailingTrivia("// defaultSeverity: Is set to DiagnosticSeverity.[severity] where severity can be Error, Warning, Hidden or Info, but can only be Error or Warning for the purposes of this tutorial").ElementAt(0), SyntaxFactory.EndOfLine("\r\n"))).WithLeadingTrivia(argument.FirstAncestorOrSelf<FieldDeclarationSyntax>().GetLeadingTrivia()), document); }
private async Task<Document> EnabledByDefaultAsync(Document document, ArgumentSyntax argument, CancellationToken c) { SyntaxGenerator generator = SyntaxGenerator.GetGenerator(document); var rule = argument.FirstAncestorOrSelf<FieldDeclarationSyntax>(); var newRule = rule.ReplaceNode(argument.Expression, generator.LiteralExpression(true)); return await ReplaceNode(argument.FirstAncestorOrSelf<FieldDeclarationSyntax>(), newRule.WithTrailingTrivia(SyntaxFactory.TriviaList(SyntaxFactory.EndOfLine("\r\n"), SyntaxFactory.Whitespace(" "), SyntaxFactory.ParseTrailingTrivia("// isEnabledByDefault: Determines whether the analyzer is enabled by default or if the user must manually enable it. Generally set to true").ElementAt(0), SyntaxFactory.EndOfLine("\r\n"))).WithLeadingTrivia(argument.FirstAncestorOrSelf<FieldDeclarationSyntax>().GetLeadingTrivia()), document); }