Beispiel #1
0
        public void TestConstructor(string category, string id, string justification, string messageId, string scope, string target)
        {
            SuppressMessageAttribute sma = new SuppressMessageAttribute(category, id)
            {
                Justification = justification,
                MessageId     = messageId,
                Scope         = scope,
                Target        = target
            };

            Assert.Equal(category, sma.Category);
            Assert.Equal(id, sma.CheckId);
            Assert.Equal(justification, sma.Justification);
            Assert.Equal(messageId, sma.MessageId);
            Assert.Equal(scope, sma.Scope);
            Assert.Equal(target, sma.Target);
        }
        public void TestConstructor(string category, string id, string justification, string messageId, string scope, string target)
        {
            SuppressMessageAttribute sma = new SuppressMessageAttribute(category, id)
            {
                Justification = justification,
                MessageId = messageId,
                Scope = scope,
                Target = target
            };

            Assert.Equal(category, sma.Category);
            Assert.Equal(id, sma.CheckId);
            Assert.Equal(justification, sma.Justification);
            Assert.Equal(messageId, sma.MessageId);
            Assert.Equal(scope, sma.Scope);
            Assert.Equal(target, sma.Target);
        }
Beispiel #3
0
        private static string ConvertToString(SuppressMessageAttribute attr)
        {
            List <string> args = new List <string>();

            args.Add(String.Format("\"{0}\"", attr.Category));
            args.Add(String.Format("\"{0}\"", attr.CheckId));
            if (!String.IsNullOrEmpty(attr.Scope))
            {
                args.Add(String.Format("Scope = \"{0}\"", attr.Scope));
            }
            if (!String.IsNullOrEmpty(attr.Target))
            {
                args.Add(String.Format("Target = \"{0}\"", attr.Target));
            }
            if (!String.IsNullOrEmpty(attr.MessageId))
            {
                args.Add(String.Format("MessageID = \"{0}\"", attr.MessageId));
            }
            return(String.Format("SuppressMessage({0})", String.Join(", ", args.ToArray())));
        }
        public static ClassDeclarationSyntax CreateWithSuppressMessageAttribute(string classTypeName, SuppressMessageAttribute suppressMessage)
        {
            if (classTypeName == null)
            {
                throw new ArgumentNullException(nameof(classTypeName));
            }

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

            return(Create(classTypeName)
                   .AddSuppressMessageAttribute(suppressMessage));
        }
Beispiel #5
0
 private static string FormatErrorMessage(SuppressMessageAttribute attr, string target, string targetType)
 {
     return(String.Format("\t({0}) {1}: {2}", targetType, target, ConvertToString(attr)));
 }
        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)));
        }