예제 #1
0
    public static PropertyDeclarationSyntax CreateListAuto(
        string dataType,
        string propertyName,
        bool initializeList = true)
    {
        var propertyDeclaration = SyntaxFactory.PropertyDeclaration(
            SyntaxFactory.GenericName(SyntaxFactory.Identifier(Microsoft.OpenApi.Models.NameConstants.List))
            .WithTypeArgumentList(SyntaxTypeArgumentListFactory.CreateWithOneItem(dataType)),
            SyntaxFactory.Identifier(propertyName))
                                  .AddModifiers(SyntaxTokenFactory.PublicKeyword())
                                  .WithAccessorList(
            SyntaxFactory.AccessorList(
                SyntaxFactory.List(
                    new[]
        {
            SyntaxAccessorDeclarationFactory.Get(),
            SyntaxAccessorDeclarationFactory.Set(),
        })));

        if (initializeList)
        {
            propertyDeclaration = propertyDeclaration.WithInitializer(
                SyntaxFactory.EqualsValueClause(
                    SyntaxFactory.ObjectCreationExpression(
                        SyntaxFactory.GenericName(SyntaxFactory.Identifier(Microsoft.OpenApi.Models.NameConstants.List))
                        .WithTypeArgumentList(SyntaxTypeArgumentListFactory.CreateWithOneItem(dataType)))
                    .WithArgumentList(
                        SyntaxFactory.ArgumentList())))
                                  .WithSemicolonToken(SyntaxTokenFactory.Semicolon());
        }

        return(propertyDeclaration);
    }
        public static PropertyDeclarationSyntax CreateAuto(string dataType, string propertyName)
        {
            var propertyDeclaration = SyntaxFactory
                                      .PropertyDeclaration(SyntaxFactory.ParseTypeName(dataType), propertyName)
                                      .AddModifiers(SyntaxTokenFactory.PublicKeyword())
                                      .AddAccessorListAccessors(
                SyntaxAccessorDeclarationFactory.Get(),
                SyntaxAccessorDeclarationFactory.Set());

            return(propertyDeclaration);
        }