Beispiel #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());
Beispiel #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)));
        }
Beispiel #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);
            }
Beispiel #4
0
 private static ArgumentListSyntax ToArgList(params ArgumentSyntax[] arguments) =>
 SyntaxFactory.ArgumentList(SyntaxHelpers.SeparatedSyntaxList(arguments));
Beispiel #5
0
 public static MethodGenerationBuilder Builder(string identifier) =>
 Builder(SyntaxHelpers.Identifier(identifier));
Beispiel #6
0
 public static ParameterListSyntax ToParameterList(
     this IEnumerable <PropertyDeclarationSyntax> properties) =>
 SyntaxHelpers.ParameterList(properties.Select(ToParameter));
Beispiel #7
0
 public static ArgumentSyntax ToArgument(
     this PropertyDeclarationSyntax propertyDeclaration) =>
 SyntaxHelpers.ArgumentFromIdentifier(propertyDeclaration.Identifier);
Beispiel #8
0
 public static ParameterSyntax ToParameter(
     this PropertyDeclarationSyntax propertyDeclaration) =>
 SyntaxHelpers.Parameter(
     propertyDeclaration.Type,
     SyntaxHelpers.LowercaseIdentifierFirstLetter(propertyDeclaration.Identifier));