Exemple #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);
            }
        }