示例#1
0
        // Internal for unit tests only.
        internal MergedDeclaration CalculateMergedRoot(LanguageCompilation compilation)
        {
            var oldRoot = _cache.MergedRoot.Value;

            if (_latestLazyRootDeclaration == null)
            {
                return(oldRoot);
            }
            else if (oldRoot == null)
            {
                return(MergedDeclaration.Create(_latestLazyRootDeclaration.Value));
            }
            else
            {
                var oldRootDeclarations = oldRoot.Declarations;
                var builder             = ArrayBuilder <SingleDeclaration> .GetInstance(oldRootDeclarations.Length + 1);

                builder.AddRange(oldRootDeclarations);
                builder.Add(_latestLazyRootDeclaration.Value);
                // Sort the root namespace declarations to match the order of SyntaxTrees.
                if (compilation != null)
                {
                    builder.Sort(new RootNamespaceLocationComparer(compilation));
                }
                return(MergedDeclaration.Create(builder.ToImmutableAndFree()));
            }
        }
示例#2
0
            public Cache(DeclarationTable table)
            {
                this.MergedRoot = new Lazy <MergedDeclaration>(
                    () => MergedDeclaration.Create(table._allOlderRootDeclarations.InInsertionOrder.AsImmutable <SingleDeclaration>()));

                this.TypeNames = new Lazy <ISet <string> >(
                    () => GetTypeNames(this.MergedRoot.Value));

                this.NamespaceNames = new Lazy <ISet <string> >(
                    () => GetNamespaceNames(this.MergedRoot.Value));

                this.ReferenceDirectives = new Lazy <ImmutableArray <ReferenceDirective> >(
                    () => MergedRoot.Value.Declarations.OfType <RootSingleDeclaration>().SelectMany(r => r.ReferenceDirectives).AsImmutable());
            }