Ejemplo n.º 1
0
 /// <summary>
 /// Creates the public properties for each Mvvm library.
 /// </summary>
 /// <returns>The public properties.</returns>
 /// <param name="property">The property to generate.</param>
 public virtual PropertyDeclarationSyntax CreatePublicProperties(Property property)
 {
     return(SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName(property.Type.FindType()), property.Name)
            .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
            .AddAccessorListAccessors(
                SyntaxFactory.AccessorDeclaration(
                    SyntaxKind.GetAccessorDeclaration)
                .WithExpressionBody(
                    SyntaxFactory.ArrowExpressionClause(
                        SyntaxFactory.MemberAccessExpression(
                            SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName(property.Name.ToCamelCase()))))
                .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
                SyntaxFactory.AccessorDeclaration(
                    SyntaxKind.SetAccessorDeclaration)
                .WithExpressionBody(
                    SyntaxFactory.ArrowExpressionClause(
                        SyntaxFactory.InvocationExpression(
                            SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName("Set")))
                        .WithArgumentList(SyntaxFactory.ArgumentList(SyntaxFactory.SeparatedList <ArgumentSyntax>(
                                                                         new SyntaxNodeOrToken[]
     {
         SyntaxFactory.Argument(SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName(property.Name.ToCamelCase())))
         .WithRefKindKeyword(SyntaxFactory.Token(SyntaxKind.RefKeyword)), SyntaxFactory.Token(SyntaxKind.CommaToken), SyntaxFactory.Argument(SyntaxFactory.IdentifierName("value"))
     })))))
                .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)))
            .WithModifiers(FormatterHelper.GenerateComment(property.Comment)));
 }
Ejemplo n.º 2
0
        private PropertyDeclarationSyntax CreateCommandProperty(Command command)
        {
            var name = command.FormatCommandName();
            var type = this.GetCommandType(command);

            return(SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName(typeof(System.Windows.Input.ICommand).ToString()), name)
                   .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
                   .AddAccessorListAccessors(
                       SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration)
                       .WithExpressionBody(
                           SyntaxFactory.ArrowExpressionClause(
                               SyntaxFactory.BinaryExpression(
                                   SyntaxKind.CoalesceExpression,
                                   SyntaxFactory.MemberAccessExpression(
                                       SyntaxKind.SimpleMemberAccessExpression,
                                       SyntaxFactory.ThisExpression(),
                                       SyntaxFactory.IdentifierName(name.ToCamelCase())),
                                   SyntaxFactory.ParenthesizedExpression(
                                       SyntaxFactory.AssignmentExpression(
                                           SyntaxKind.SimpleAssignmentExpression,
                                           SyntaxFactory.MemberAccessExpression(
                                               SyntaxKind.SimpleMemberAccessExpression,
                                               SyntaxFactory.ThisExpression(),
                                               SyntaxFactory.IdentifierName(name.ToCamelCase())),
                                           SyntaxFactory.ObjectCreationExpression(SyntaxFactory.IdentifierName(type))
                                           .WithArgumentList(this.GetCommandMethodSyntax(command)))))))
                       .WithSemicolonToken(SyntaxFactory.Token(
                                               SyntaxFactory.TriviaList(),
                                               SyntaxKind.SemicolonToken,
                                               SyntaxFactory.TriviaList(SyntaxFactory.Comment(this.GenerateCommandComment(command))))))
                   .WithModifiers(FormatterHelper.GenerateComment(command.Comment)));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates the public properties for each Mvvm library.
 /// </summary>
 /// <returns>The public properties.</returns>
 /// <param name="property">The property to generate.</param>
 public override PropertyDeclarationSyntax CreatePublicProperties(Property property)
 {
     return(SyntaxFactory.PropertyDeclaration(SyntaxFactory.ParseTypeName(property.Type.FindType()), property.Name)
            .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
            .AddAccessorListAccessors(
                SyntaxFactory.AccessorDeclaration(
                    SyntaxKind.GetAccessorDeclaration)
                .WithExpressionBody(
                    SyntaxFactory.ArrowExpressionClause(
                        SyntaxFactory.MemberAccessExpression(
                            SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ThisExpression(), SyntaxFactory.IdentifierName(property.Name.ToCamelCase()))))
                .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)),
                SyntaxFactory.AccessorDeclaration(
                    SyntaxKind.SetAccessorDeclaration)
                .WithBody(
                    SyntaxFactory.Block(
                        SyntaxFactory.ExpressionStatement(
                            SyntaxFactory.AssignmentExpression(
                                SyntaxKind.SimpleAssignmentExpression,
                                SyntaxFactory.IdentifierName(property.Name.ToCamelCase()),
                                SyntaxFactory.IdentifierName("value"))),
                        SyntaxFactory.ExpressionStatement(
                            SyntaxFactory.InvocationExpression(
                                SyntaxFactory.IdentifierName("RaisePropertyChanged"))))))
            .WithModifiers(FormatterHelper.GenerateComment(property.Comment)));
 }