Ejemplo n.º 1
0
        public static TSyntax BuildTypeParameterSyntax <TSyntax>(IHasTypeParameters itemAsT, TSyntax node,
                                                                 WhitespaceKindLookup whitespaceLookup,
                                                                 Func <TSyntax, TypeParameterListSyntax, TSyntax> addTypeParameters,
                                                                 Func <TSyntax, SyntaxList <TypeParameterConstraintClauseSyntax>, TSyntax> addTypeParameterConstraints)
            where TSyntax : SyntaxNode
        {
            // This works oddly because it uncollapses the list
            // This code is largely repeated in interface and class factories, but is very hard to refactor because of shallow Roslyn (Microsoft) architecture
            var typeParamsAndConstraints = itemAsT.TypeParameters
                                           .SelectMany(x => RDom.CSharp.GetSyntaxGroup(x))
                                           .ToList();

            var typeParameterSyntaxList = BuildSyntaxHelpers.GetTypeParameterSyntaxList(
                typeParamsAndConstraints, itemAsT.Whitespace2Set, whitespaceLookup);

            if (typeParameterSyntaxList != null)
            {
                node = addTypeParameters(node, typeParameterSyntaxList);
                var clauses = BuildSyntaxHelpers.GetTypeParameterConstraintList(
                    typeParamsAndConstraints, itemAsT.Whitespace2Set, whitespaceLookup);
                if (clauses.Any())
                {
                    node = addTypeParameterConstraints(node, clauses);
                }
            }
            return(node);
        }