Esempio n. 1
0
        internal static NamespaceSymbol Create(
            NamespaceExtent extent,
            NamespaceSymbol containingNamespace,
            ImmutableArray <NamespaceSymbol> namespacesToMerge,
            string nameOpt = null
            )
        {
            // Currently, if we are just merging 1 namespace, we just return the namespace itself.
            // This is by far the most efficient, because it means that we don't create merged
            // namespaces (which have a fair amount of memory overhead) unless there is actual
            // merging going on. However, it means that the child namespace of a Compilation extent
            // namespace may be a Module extent namespace, and the containing of that module extent
            // namespace will be another module extent namespace. This is basically no different
            // than type members of namespaces, so it shouldn't be TOO unexpected.

            // EDMAURER if the caller is supplying a name, then produce the merged namespace with
            // the new name even if only a single namespace was provided. This behavior was introduced
            // to support nice extern alias error reporting.

            Debug.Assert(namespacesToMerge.Length != 0);

            return((namespacesToMerge.Length == 1 && nameOpt == null)
              ? namespacesToMerge[0]
              : new MergedNamespaceSymbol(extent, containingNamespace, namespacesToMerge, nameOpt));
        }
Esempio n. 2
0
        // Constructor. Use static Create method to create instances.
        private MergedNamespaceSymbol(NamespaceExtent extent, NamespaceSymbol containingNamespace, ImmutableArray <NamespaceSymbol> namespacesToMerge, string nameOpt)
        {
            this.extent              = extent;
            this.namespacesToMerge   = namespacesToMerge;
            this.containingNamespace = containingNamespace;
            this.cachedLookup        = new CachingDictionary <string, Symbol>(SlowGetChildrenOfName, SlowGetChildNames, EqualityComparer <string> .Default);
            this.nameOpt             = nameOpt;

#if DEBUG
            // We shouldn't merged namespaces that are already merged.
            foreach (NamespaceSymbol ns in namespacesToMerge)
            {
                Debug.Assert(ns.ConstituentNamespaces.Length == 1);
            }
#endif
        }