예제 #1
0
        private static AttributeArgumentListSyntax GenerateAttributeArgumentList(AttributeData attribute)
        {
            if (attribute.ConstructorArguments.Length == 0 && attribute.NamedArguments.Length == 0)
            {
                return(null);
            }

            var arguments = new List <AttributeArgumentSyntax>();

            arguments.AddRange(attribute.ConstructorArguments.Select(c =>
                                                                     SyntaxFactory.AttributeArgument(ExpressionGenerator.GenerateExpression(c))));

            arguments.AddRange(attribute.NamedArguments.Select(kvp =>
                                                               SyntaxFactory.AttributeArgument(
                                                                   SyntaxFactory.NameEquals(SyntaxFactory.IdentifierName(kvp.Key)), null,
                                                                   ExpressionGenerator.GenerateExpression(kvp.Value))));

            return(SyntaxFactory.AttributeArgumentList(SyntaxFactory.SeparatedList(arguments)));
        }