Exemple #1
0
        public static AttributeSyntax EmitSyntax(AttributeDescription description)
        {
            var syntax = SyntaxFactory.Attribute(SyntaxHelpers.GetTypeFullNameSyntax(description.AttributeType, stripSuffix: "Attribute"));

            if (description.ConstructorArguments.Count > 0 || description.PropertyValues.Count > 0)
            {
                syntax = syntax
                         .WithArgumentList(
                    SyntaxFactory.AttributeArgumentList(
                        SyntaxFactory.SeparatedList <AttributeArgumentSyntax>(
                            description.ConstructorArguments.Select(arg =>
                                                                    SyntaxFactory.AttributeArgument(SyntaxHelpers.GetLiteralSyntax(arg)))
                            .Concat(description.PropertyValues.Select(pv =>
                                                                      SyntaxFactory.AttributeArgument(ExpressionSyntaxEmitter.EmitSyntax(pv.Value))
                                                                      .WithNameEquals(SyntaxFactory.NameEquals(SyntaxFactory.IdentifierName(pv.Name)))
                                                                      ))
                            )
                        )
                    );
            }

            return(syntax);
        }
Exemple #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected BaseTypeSyntax ToBaseTypeSyntax(TypeMember baseTypeMember)
        {
            return(SyntaxFactory.SimpleBaseType(SyntaxHelpers.GetTypeFullNameSyntax(baseTypeMember)));
        }