Exemplo n.º 1
0
        /// <summary>
        /// Create symbols for nested types and initialize types map.
        /// </summary>
        private void LazyInitializeTypes(IEnumerable <IGrouping <string, TypeDefinitionHandle> > typeGroups)
        {
            if (this.lazyTypes == null)
            {
                var moduleSymbol = ContainingPEModule;

                var children = ArrayBuilder <PENamedTypeSymbol> .GetInstance();

                var skipCheckForPiaType = !moduleSymbol.Module.ContainsNoPiaLocalTypes();
                Dictionary <string, TypeDefinitionHandle> noPiaLocalTypes = null;

                foreach (var g in typeGroups)
                {
                    foreach (var t in g)
                    {
                        if (skipCheckForPiaType || !moduleSymbol.Module.IsNoPiaLocalType(t))
                        {
                            children.Add(PENamedTypeSymbol.Create(moduleSymbol, this, t, g.Key));
                        }
                        else
                        {
                            try
                            {
                                string typeDefName = moduleSymbol.Module.GetTypeDefNameOrThrow(t);

                                if (noPiaLocalTypes == null)
                                {
                                    noPiaLocalTypes = new Dictionary <string, TypeDefinitionHandle>(StringOrdinalComparer.Instance);
                                }

                                noPiaLocalTypes[typeDefName] = t;
                            }
                            catch (BadImageFormatException)
                            { }
                        }
                    }
                }

                var typesDict = children.ToDictionary(c => c.Name, StringOrdinalComparer.Instance);
                children.Free();

                if (noPiaLocalTypes != null)
                {
                    Interlocked.CompareExchange(ref _lazyNoPiaLocalTypes, noPiaLocalTypes, null);
                }

                var original = Interlocked.CompareExchange(ref this.lazyTypes, typesDict, null);

                // Build cache of TypeDef Tokens
                // Potentially this can be done in the background.
                if (original == null)
                {
                    moduleSymbol.OnNewTypeDeclarationsLoaded(typesDict);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create symbols for nested types and initialize types map.
        /// </summary>
        protected void LazyInitializeTypes(IEnumerable <IGrouping <string, TypeDefinitionHandle> > typeGroups)
        {
            if (_types == null)
            {
                var moduleSymbol = ContainingPEModule;

                var children = ArrayBuilder <NamedTypeSymbol> .GetInstance();

                var skipCheckForPiaType = !moduleSymbol.Module.ContainsNoPiaLocalTypes();

                foreach (var g in typeGroups)
                {
                    foreach (var t in g)
                    {
                        if (skipCheckForPiaType || !moduleSymbol.Module.IsNoPiaLocalType(t))
                        {
                            children.Add(PENamedTypeSymbol.Create(moduleSymbol, this, t, g.Key));
                        }
                        else
                        {
                            // Pia ignored
                        }
                    }
                }

                var typesDict = children.ToDictionary(c => MetadataHelpers.BuildQualifiedName(c.NamespaceName, c.Name));
                children.Free();

                //if (noPiaLocalTypes != null)
                //{
                //    Interlocked.CompareExchange(ref _lazyNoPiaLocalTypes, noPiaLocalTypes, null);
                //}

                Interlocked.CompareExchange(ref _types, typesDict, null);
            }
        }