public GenericInfo RemoveConstraintClauses() { if (!ConstraintClauses.Any()) { return(this); } TypeParameterConstraintClauseSyntax first = ConstraintClauses.First(); SyntaxToken token = first.WhereKeyword.GetPreviousToken(); SyntaxTriviaList trivia = token.TrailingTrivia.EmptyIfWhitespace() .AddRange(first.GetLeadingTrivia().EmptyIfWhitespace()) .AddRange(ConstraintClauses.Last().GetTrailingTrivia()); return(Create(Declaration.ReplaceToken(token, token.WithTrailingTrivia(trivia))) .WithConstraintClauses(default(SyntaxList <TypeParameterConstraintClauseSyntax>))); }
public static SyntaxNode RemoveConstraintClauses(SyntaxNode node) { switch (node.Kind()) { case SyntaxKind.ClassDeclaration: { var classDeclaration = (ClassDeclarationSyntax)node; SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = classDeclaration.ConstraintClauses; if (!constraintClauses.Any()) { break; } TypeParameterConstraintClauseSyntax first = constraintClauses.First(); SyntaxToken token = first.WhereKeyword.GetPreviousToken(); SyntaxTriviaList trivia = token.TrailingTrivia.EmptyIfWhitespace() .AddRange(first.GetLeadingTrivia().EmptyIfWhitespace()) .AddRange(constraintClauses.Last().GetTrailingTrivia()); return(classDeclaration .ReplaceToken(token, token.WithTrailingTrivia(trivia)) .WithConstraintClauses(default(SyntaxList <TypeParameterConstraintClauseSyntax>))); } case SyntaxKind.InterfaceDeclaration: { var interfaceDeclaration = (InterfaceDeclarationSyntax)node; SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = interfaceDeclaration.ConstraintClauses; if (!constraintClauses.Any()) { break; } TypeParameterConstraintClauseSyntax first = constraintClauses.First(); SyntaxToken token = first.WhereKeyword.GetPreviousToken(); SyntaxTriviaList trivia = token.TrailingTrivia.EmptyIfWhitespace() .AddRange(first.GetLeadingTrivia().EmptyIfWhitespace()) .AddRange(constraintClauses.Last().GetTrailingTrivia()); return(interfaceDeclaration .ReplaceToken(token, token.WithTrailingTrivia(trivia)) .WithConstraintClauses(default(SyntaxList <TypeParameterConstraintClauseSyntax>))); } case SyntaxKind.StructDeclaration: { var structDeclaration = (StructDeclarationSyntax)node; SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = structDeclaration.ConstraintClauses; if (!constraintClauses.Any()) { break; } TypeParameterConstraintClauseSyntax first = constraintClauses.First(); SyntaxToken token = first.WhereKeyword.GetPreviousToken(); SyntaxTriviaList trivia = token.TrailingTrivia.EmptyIfWhitespace() .AddRange(first.GetLeadingTrivia().EmptyIfWhitespace()) .AddRange(constraintClauses.Last().GetTrailingTrivia()); return(structDeclaration .ReplaceToken(token, token.WithTrailingTrivia(trivia)) .WithConstraintClauses(default(SyntaxList <TypeParameterConstraintClauseSyntax>))); } case SyntaxKind.DelegateDeclaration: { var delegateDeclaration = (DelegateDeclarationSyntax)node; SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = delegateDeclaration.ConstraintClauses; if (!constraintClauses.Any()) { break; } TypeParameterConstraintClauseSyntax first = constraintClauses.First(); SyntaxToken token = first.WhereKeyword.GetPreviousToken(); SyntaxTriviaList trivia = token.TrailingTrivia.EmptyIfWhitespace() .AddRange(first.GetLeadingTrivia().EmptyIfWhitespace()) .AddRange(constraintClauses.Last().GetTrailingTrivia()); return(delegateDeclaration .ReplaceToken(token, token.WithTrailingTrivia(trivia)) .WithConstraintClauses(default(SyntaxList <TypeParameterConstraintClauseSyntax>))); } case SyntaxKind.MethodDeclaration: { var methodDeclaration = (MethodDeclarationSyntax)node; SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = methodDeclaration.ConstraintClauses; if (!constraintClauses.Any()) { break; } TypeParameterConstraintClauseSyntax first = constraintClauses.First(); SyntaxToken token = first.WhereKeyword.GetPreviousToken(); SyntaxTriviaList trivia = token.TrailingTrivia.EmptyIfWhitespace() .AddRange(first.GetLeadingTrivia().EmptyIfWhitespace()) .AddRange(constraintClauses.Last().GetTrailingTrivia()); return(methodDeclaration .ReplaceToken(token, token.WithTrailingTrivia(trivia)) .WithConstraintClauses(default(SyntaxList <TypeParameterConstraintClauseSyntax>))); } case SyntaxKind.LocalFunctionStatement: { var localFunctionStatement = (LocalFunctionStatementSyntax)node; SyntaxList <TypeParameterConstraintClauseSyntax> constraintClauses = localFunctionStatement.ConstraintClauses; if (!constraintClauses.Any()) { break; } TypeParameterConstraintClauseSyntax first = constraintClauses.First(); SyntaxToken token = first.WhereKeyword.GetPreviousToken(); SyntaxTriviaList trivia = token.TrailingTrivia.EmptyIfWhitespace() .AddRange(first.GetLeadingTrivia().EmptyIfWhitespace()) .AddRange(constraintClauses.Last().GetTrailingTrivia()); return(localFunctionStatement .ReplaceToken(token, token.WithTrailingTrivia(trivia)) .WithConstraintClauses(default(SyntaxList <TypeParameterConstraintClauseSyntax>))); } } return(node); }