public CSharpSyntaxNode Convert(ClassDeclaration node) { ClassDeclarationSyntax csClass = SyntaxFactory .ClassDeclaration(node.Name.Text) .AddModifiers(node.Modifiers.ToCsNodes <SyntaxToken>()) .AddMembers(node.Members.ToCsNodes <MemberDeclarationSyntax>()); foreach (TypeParameter typeParameter in node.TypeParameters) { csClass = csClass.AddTypeParameterListParameters(typeParameter.ToCsNode <TypeParameterSyntax>()); if (typeParameter.Constraint != null) { csClass = csClass.AddConstraintClauses(SyntaxFactory .TypeParameterConstraintClause(typeParameter.Name.Text) .AddConstraints(SyntaxFactory.TypeConstraint(typeParameter.Constraint.ToCsNode <TypeSyntax>())) ); } } List <Node> baseTypes = node.GetBaseTypes(this.Context.Config.PreferTypeScriptType); if (baseTypes.Count > 0) { csClass = csClass.AddBaseListTypes(baseTypes.ToCsNodes <BaseTypeSyntax>()); } if (node.JsDoc.Count > 0) { csClass = csClass.WithLeadingTrivia(SyntaxFactory.Trivia(node.JsDoc[0].ToCsNode <DocumentationCommentTriviaSyntax>())); } return(csClass); }
private static ClassDeclarationSyntax GetNewNode( ClassDeclarationSyntax classDeclaration, TypeParameterConstraintSyntax constraint, SemanticModel semanticModel) { string name = GetTypeParameterName(classDeclaration.OpenBraceToken.SpanStart, semanticModel); ClassDeclarationSyntax newNode = classDeclaration.AddTypeParameterListParameters(TypeParameter(Identifier(name).WithRenameAnnotation())); if (constraint != null) { newNode = newNode.AddConstraintClauses(TypeParameterConstraintClause(name, constraint)); } return(newNode); }
private static SyntaxNode GetNewNode( ClassDeclarationSyntax classDeclaration, TypeParameterConstraintSyntax constraint, SemanticModel semanticModel, CancellationToken cancellationToken) { TypeParameterListSyntax typeParameterList = classDeclaration.TypeParameterList; INamedTypeSymbol classSymbol = semanticModel.GetDeclaredSymbol(classDeclaration, cancellationToken); string name = GetTypeParameterName(classDeclaration.OpenBraceToken.SpanStart, semanticModel); ClassDeclarationSyntax newNode = classDeclaration.AddTypeParameterListParameters(TypeParameter(Identifier(name).WithRenameAnnotation())); if (constraint != null) { newNode = newNode.AddConstraintClauses(TypeParameterConstraintClause(name, constraint)); } return(newNode); }