public static ClassDeclarationSyntax AddSuppressMessageAttribute(this ClassDeclarationSyntax classDeclaration, SuppressMessageAttribute suppressMessage)
        {
            if (classDeclaration == null)
            {
                throw new ArgumentNullException(nameof(classDeclaration));
            }

            if (suppressMessage == null)
            {
                throw new ArgumentNullException(nameof(suppressMessage));
            }

            if (string.IsNullOrEmpty(suppressMessage.Justification))
            {
                throw new ArgumentException(nameof(suppressMessage.Justification));
            }

            var attributeArgumentList = SyntaxFactory.AttributeArgumentList(
                SyntaxFactory.SeparatedList <AttributeArgumentSyntax>(SyntaxFactory.NodeOrTokenList(
                                                                          SyntaxFactory.AttributeArgument(SyntaxLiteralExpressionFactory.Create(suppressMessage.Category)),
                                                                          SyntaxTokenFactory.Comma(),
                                                                          SyntaxFactory.AttributeArgument(SyntaxLiteralExpressionFactory.Create(suppressMessage.CheckId)),
                                                                          SyntaxTokenFactory.Comma(),
                                                                          SyntaxFactory.AttributeArgument(SyntaxLiteralExpressionFactory.Create(suppressMessage.Justification !))
                                                                          .WithNameEquals(
                                                                              SyntaxNameEqualsFactory.Create(nameof(SuppressMessageAttribute.Justification))
                                                                              .WithEqualsToken(SyntaxTokenFactory.Equals())))));

            return(classDeclaration
                   .AddAttributeLists(SyntaxAttributeListFactory.Create(nameof(SuppressMessageAttribute), attributeArgumentList)));
        }
        public static ClassDeclarationSyntax AddGeneratedCodeAttribute(this ClassDeclarationSyntax classDeclaration, string toolName, string version)
        {
            if (classDeclaration == null)
            {
                throw new ArgumentNullException(nameof(classDeclaration));
            }

            if (toolName == null)
            {
                throw new ArgumentNullException(nameof(toolName));
            }

            if (version == null)
            {
                throw new ArgumentNullException(nameof(version));
            }

            var attributeArgumentList = SyntaxFactory.AttributeArgumentList(
                SyntaxFactory.SeparatedList <AttributeArgumentSyntax>(SyntaxFactory.NodeOrTokenList(
                                                                          SyntaxFactory.AttributeArgument(SyntaxLiteralExpressionFactory.Create(toolName)),
                                                                          SyntaxTokenFactory.Comma(),
                                                                          SyntaxFactory.AttributeArgument(SyntaxLiteralExpressionFactory.Create(version)))));

            return(classDeclaration
                   .AddAttributeLists(SyntaxAttributeListFactory.Create(nameof(GeneratedCodeAttribute), attributeArgumentList)));
        }
 private static SyntaxNode AddAttribute(SyntaxNode root, ClassDeclarationSyntax classNode,
   string name)
 {
   var attribute = SyntaxFactory.Attribute(SyntaxFactory.ParseName(name));
   var attributeList = SyntaxFactory.AttributeList(SyntaxFactory.SeparatedList<AttributeSyntax>().Add(attribute));
   var newClassNode = classNode.AddAttributeLists(attributeList);
   return root.ReplaceNode(classNode, newClassNode);
 }
 private ClassDeclarationSyntax AddAttribute(ClassDeclarationSyntax classDecl, string attributeName)
 {
     var newAttributes = SyntaxFactory.AttributeList(
                             SyntaxFactory.SingletonSeparatedList(
                                 SyntaxFactory.Attribute(SyntaxFactory.IdentifierName(attributeName))
                             )
                         );
     classDecl = classDecl.AddAttributeLists(newAttributes);
     return classDecl;
 }