Пример #1
0
 public static ConstructorDeclarationSyntax FromParameterList(
     SyntaxToken identifier,
     ParameterListSyntax parameterList) =>
 SyntaxFactory.ConstructorDeclaration(
     SyntaxHelpers.EmptyAttributeList(),
     SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)),
     identifier.WithoutTrivia(),
     parameterList,
     default(ConstructorInitializerSyntax),
     SyntaxFactory.Block());
Пример #2
0
        public static ConstructorDeclarationSyntax FromPropertiesWithAssignments(
            SyntaxToken identifier,
            IList <PropertyDeclarationSyntax> properties)
        {
            var parameterList       = properties.ToParameterList();
            var propertyAssignments = properties.Select(
                p => SyntaxFactory.ExpressionStatement(
                    ExpressionGenerationHelper.SimpleAssignment(
                        p.Identifier, SyntaxHelpers.LowercaseIdentifierFirstLetter(p.Identifier))));

            return(SyntaxFactory.ConstructorDeclaration(
                       SyntaxHelpers.EmptyAttributeList(),
                       SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PublicKeyword)),
                       identifier.WithoutTrivia(),
                       parameterList,
                       default(ConstructorInitializerSyntax),
                       SyntaxFactory.Block(propertyAssignments)));
        }
Пример #3
0
            public MethodDeclarationSyntax Build()
            {
                var methodDeclaration = SyntaxFactory.MethodDeclaration(
                    SyntaxHelpers.EmptyAttributeList(),
                    SyntaxFactory.TokenList(modifiers),
                    returnType,
                    default(ExplicitInterfaceSpecifierSyntax),
                    identifier,
                    typeParameters,
                    SyntaxHelpers.ParameterList(parameters),
                    typeConstraints != null ?
                    SyntaxFactory.List(typeConstraints)
                        : SyntaxFactory.List <TypeParameterConstraintClauseSyntax>(),
                    blockBody,
                    expressionBody);

                if (expressionBody != null ||
                    (expressionBody == null && blockBody == null))
                {
                    methodDeclaration = methodDeclaration.WithSemicolonToken(Tokens.Semicolon);
                }

                return(methodDeclaration);
            }
Пример #4
0
 private static ArgumentListSyntax ToArgList(params ArgumentSyntax[] arguments) =>
 SyntaxFactory.ArgumentList(SyntaxHelpers.SeparatedSyntaxList(arguments));
Пример #5
0
 public static MethodGenerationBuilder Builder(string identifier) =>
 Builder(SyntaxHelpers.Identifier(identifier));
Пример #6
0
 public static ParameterListSyntax ToParameterList(
     this IEnumerable <PropertyDeclarationSyntax> properties) =>
 SyntaxHelpers.ParameterList(properties.Select(ToParameter));
Пример #7
0
 public static ArgumentSyntax ToArgument(
     this PropertyDeclarationSyntax propertyDeclaration) =>
 SyntaxHelpers.ArgumentFromIdentifier(propertyDeclaration.Identifier);
Пример #8
0
 public static ParameterSyntax ToParameter(
     this PropertyDeclarationSyntax propertyDeclaration) =>
 SyntaxHelpers.Parameter(
     propertyDeclaration.Type,
     SyntaxHelpers.LowercaseIdentifierFirstLetter(propertyDeclaration.Identifier));