Example #1
0
        /// <summary>
        /// Determines how many type parameters of the <see cref="OriginalDeclaration"/> should the <see cref="CurrentDeclaration"/> have.
        /// </summary>
        /// <param name="count">Number of type parameters to take.</param>
        public void WithTypeParameters(int count)
        {
            if (DefaultParamUtilities.TryUpdateTypeParameters(CurrentDeclaration.TypeParameterList, count, out TypeParameterListSyntax? updated))
            {
                CurrentDeclaration = CurrentDeclaration.WithTypeParameterList(updated);
            }

            CheckDirectCall(count);
            SyntaxTokenList modifiers = CurrentDeclaration.Modifiers;

            if (!modifiers.Any())
            {
                SyntaxTriviaList trivia = CurrentDeclaration.ReturnType.GetLeadingTrivia();

                if (trivia.Any())
                {
                    trivia             = trivia.RemoveAt(trivia.Count - 1);
                    CurrentDeclaration = CurrentDeclaration.WithReturnType(CurrentDeclaration.ReturnType.WithLeadingTrivia(trivia));
                }
            }

            if (DefaultParamUtilities.TryAddNewModifier(_newModifierIndexes, count, _numNonDefaultParam, ref modifiers))
            {
                CurrentDeclaration = CurrentDeclaration.WithModifiers(modifiers);
            }
        }
        /// <summary>
        /// Determines how many type parameters of the <see cref="OriginalDeclaration"/> should the <see cref="CurrentDeclaration"/> have.
        /// </summary>
        /// <param name="count">Number of type parameters to take.</param>
        public void WithTypeParameters(int count)
        {
            if (DefaultParamUtilities.TryUpdateTypeParameters(CurrentDeclaration.TypeParameterList, count, out TypeParameterListSyntax? updated))
            {
                CurrentDeclaration = CurrentDeclaration.WithTypeParameterList(updated);
            }

            SyntaxTokenList modifiers = CurrentDeclaration.Modifiers;

            if (!modifiers.Any())
            {
                SyntaxTriviaList trivia = CurrentDeclaration.DelegateKeyword.LeadingTrivia;

                if (trivia.Any())
                {
                    trivia             = trivia.RemoveAt(trivia.Count - 1);
                    CurrentDeclaration = CurrentDeclaration.WithDelegateKeyword(CurrentDeclaration.DelegateKeyword.WithLeadingTrivia(trivia));
                }
            }

            if (DefaultParamUtilities.TryAddNewModifier(_newModifierIndexes, count, _numNonDefaultParam, ref modifiers))
            {
                CurrentDeclaration = CurrentDeclaration.WithModifiers(modifiers);
            }
        }
Example #3
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);
        }