Beispiel #1
0
        public CSharpSyntaxNode Convert(Constructor node)
        {
            if (!(node.Parent is ClassDeclaration tsClassNode))
            {
                return(null);
            }

            ConstructorDeclarationSyntax csCtor = SyntaxFactory.ConstructorDeclaration(tsClassNode.Name.Text);

            csCtor = csCtor.AddModifiers(node.Modifiers.ToCsNodes <SyntaxToken>());
            csCtor = csCtor.AddParameterListParameters(node.Parameters.ToCsNodes <ParameterSyntax>());

            CallExpression baseNode =
                node.Base is ExpressionStatement
                ? ((ExpressionStatement)node.Base).Expression as CallExpression
                : node.Base as CallExpression;

            if (baseNode != null)
            {
                ArgumentSyntax[] csArgs = this.ToArgumentList(baseNode.Arguments);
                csCtor = csCtor.WithInitializer(SyntaxFactory.ConstructorInitializer(SyntaxKind.BaseConstructorInitializer).AddArgumentListArguments(csArgs));
            }

            if (node.JsDoc.Count > 0)
            {
                csCtor = csCtor.WithLeadingTrivia(SyntaxFactory.Trivia(node.JsDoc[0].ToCsNode <DocumentationCommentTriviaSyntax>()));
            }

            return(csCtor.WithBody(node.Body.ToCsNode <BlockSyntax>()));
        }
 public static ConstructorDeclarationSyntax AddModifiers(this ConstructorDeclarationSyntax cl, params SyntaxKind[] modifiers)
 {
     if (modifiers == null)
     {
         return(cl);
     }
     return(cl.AddModifiers(modifiers.Select(x => SyntaxFactory.Token(x)).ToArray()));
 }
Beispiel #3
0
 public static ConstructorDeclarationSyntax AddModifiers(this ConstructorDeclarationSyntax syntax, params SyntaxKind[] modifier)
 {
     return(syntax.AddModifiers(modifier.Select(Token).ToArray()));
 }
Beispiel #4
0
 public static ConstructorDeclarationSyntax WithModifiers(this ConstructorDeclarationSyntax node, params SyntaxKind[] modifiers)
 {
     return(node.AddModifiers(CreateModifiers(modifiers)));
 }