Exemplo n.º 1
0
        /// <summary>
        /// Replaces <see cref="TypeParameterConstraintClauseSyntax"/>es of the <see cref="CurrentDeclaration"/> with the specified collection of <see cref="TypeParameterConstraintClauseSyntax"/>es.
        /// </summary>
        /// <param name="constraintClauses">Collection of <see cref="TypeParameterConstraintClauseSyntax"/> to apply to the <see cref="CurrentDeclaration"/>.</param>
        public void WithConstraintClauses(IEnumerable <TypeParameterConstraintClauseSyntax> constraintClauses)
        {
            SyntaxList <TypeParameterConstraintClauseSyntax> clauses = DefaultParamUtilities.ApplyConstraints(constraintClauses, _numOriginalConstraints);

            if (clauses.Any())
            {
                clauses = clauses.Replace(clauses.Last(), clauses.Last().WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed));
            }
            else if (!_symbol.IsAbstract)
            {
                CurrentDeclaration = CurrentDeclaration.WithParameterList(CurrentDeclaration.ParameterList.WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed));
            }

            CurrentDeclaration = CurrentDeclaration.WithConstraintClauses(clauses);
        }
        /// <summary>
        /// Replaces <see cref="TypeParameterConstraintClauseSyntax"/>es of the <see cref="CurrentDeclaration"/> with the specified collection of <see cref="TypeParameterConstraintClauseSyntax"/>es.
        /// </summary>
        /// <param name="constraintClauses">Collection of <see cref="TypeParameterConstraintClauseSyntax"/> to apply to the <see cref="CurrentDeclaration"/>.</param>
        public void WithConstraintClauses(IEnumerable <TypeParameterConstraintClauseSyntax> constraintClauses)
        {
            SyntaxList <TypeParameterConstraintClauseSyntax> clauses = DefaultParamUtilities.ApplyConstraints(constraintClauses, _numOriginalConstraints);

            if (clauses.Any())
            {
                clauses = clauses.Replace(clauses.Last(), clauses.Last().WithTrailingTrivia(null));
            }
            else if (CurrentDeclaration.ConstraintClauses.Any())
            {
                CurrentDeclaration = CurrentDeclaration.WithParameterList(CurrentDeclaration.ParameterList.WithoutTrailingTrivia());
            }

            CurrentDeclaration = CurrentDeclaration.WithConstraintClauses(clauses);
        }