public void ShouldParseInteger(int value)
        {
            // Act
            var result = SyntaxLiteralExpressionFactory.Create(value);

            // Assert
            Assert.Equal(SyntaxKind.NumericLiteralExpression, result.Kind());
            Assert.Equal(value.ToString(CultureInfo.InvariantCulture), result.ToString());
        }
        public void ShouldParseInvalidNumberAsString(string value)
        {
            // Act
            var result = SyntaxLiteralExpressionFactory.Create(value);

            // Assert
            Assert.Equal(SyntaxKind.StringLiteralExpression, result.Kind());
            Assert.Equal($"\"{value}\"", result.ToString());
        }
        public void ShouldParseNumber(string value)
        {
            // Act
            var result = SyntaxLiteralExpressionFactory.Create(value, SyntaxKind.NumericLiteralExpression);

            // Assert
            Assert.Equal(SyntaxKind.NumericLiteralExpression, result.Kind());
            Assert.Equal(value.Replace(",", ".", StringComparison.Ordinal), result.ToString());
        }
Ejemplo n.º 4
0
        public static InterfaceDeclarationSyntax AddGeneratedCodeAttribute(this InterfaceDeclarationSyntax interfaceDeclaration, string toolName, string version)
        {
            if (interfaceDeclaration == null)
            {
                throw new ArgumentNullException(nameof(interfaceDeclaration));
            }

            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(interfaceDeclaration
                   .AddAttributeLists(SyntaxAttributeListFactory.Create(nameof(GeneratedCodeAttribute), attributeArgumentList)));
        }
        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 void ShouldFailOnInvalidNumber(string value)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => SyntaxLiteralExpressionFactory.Create(value, SyntaxKind.NumericLiteralExpression));
 }