示例#1
0
        private async Task <Document> AddOperatorType(
            Document document,
            CompilationUnitSyntax root,
            ImmutableDictionary <string, ImmutableArray <ITypeSymbol> > constraintDic)
        {
            bool hasMethod = false;

            var usings = root.Usings.ToNamespaceHashSet();

            MemberDeclarationSyntax[] newMembers = new MemberDeclarationSyntax[constraintDic.Count];
            foreach (var(p, i) in constraintDic.Select((p, i) => (p, i)))
            {
                bool m;
                (newMembers[i], m) = CreateOperatorTypeSyntax(p.Key, p.Value, usings);
                hasMethod         |= m;
            }

            root = root.AddMembers(newMembers);
            if (hasMethod && !usings.Contains(System_Runtime_CompilerServices))
            {
                root = SyntaxHelpers.AddSystem_Runtime_CompilerServicesSyntax(root);
            }

            return(document.WithSyntaxRoot(root));
        }
示例#2
0
        private async Task <Document> AddAggressiveInlining(
            Document document, CompilationUnitSyntax root,
            TypeDeclarationSyntax typeDeclarationSyntax, CancellationToken cancellationToken)
        {
            root = root.ReplaceNode(typeDeclarationSyntax,
                                    new AddAggressiveInliningRewriter(await document.GetSemanticModelAsync(cancellationToken)).Visit(typeDeclarationSyntax));

            if (!root.Usings.ToNamespaceHashSet().Contains(System_Runtime_CompilerServices))
            {
                root = SyntaxHelpers.AddSystem_Runtime_CompilerServicesSyntax(root);
            }

            return(document.WithSyntaxRoot(root));
        }