Esempio n. 1
0
        private static SyntaxNode GetNewNode(
            DelegateDeclarationSyntax delegateDeclaration,
            TypeParameterConstraintSyntax constraint,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            TypeParameterListSyntax typeParameterList = delegateDeclaration.TypeParameterList;

            INamedTypeSymbol delegateSymbol = semanticModel.GetDeclaredSymbol(delegateDeclaration, cancellationToken);

            int position = (typeParameterList != null)
                ? typeParameterList.SpanStart
                : delegateDeclaration.Identifier.SpanStart;

            string name = GetTypeParameterName(position, semanticModel);

            DelegateDeclarationSyntax newNode = delegateDeclaration.AddTypeParameterListParameters(TypeParameter(Identifier(name).WithRenameAnnotation()));

            if (constraint != null)
            {
                newNode = newNode.AddConstraintClauses(TypeParameterConstraintClause(name, constraint));
            }

            return(newNode);
        }
Esempio n. 2
0
        private DelegateDeclarationSyntax CreateDelegateDeclaration(TypeAliasDeclaration node)
        {
            FunctionType fn = node.Type as FunctionType;

            DelegateDeclarationSyntax csDelegateDeclaration = SyntaxFactory
                                                              .DelegateDeclaration(fn.Type.ToCsNode <TypeSyntax>(), node.Name.Text)
                                                              .AddParameterListParameters(fn.Parameters.ToCsNodes <ParameterSyntax>())
                                                              .AddModifiers(node.Modifiers.ToCsNodes <SyntaxToken>());;

            if (node.TypeParameters.Count > 0)
            {
                csDelegateDeclaration = csDelegateDeclaration.AddTypeParameterListParameters(node.TypeParameters.ToCsNodes <TypeParameterSyntax>());
            }
            return(csDelegateDeclaration);
        }