예제 #1
0
 private static void VisitTopLevelType(TypeReferenceIndexer noPiaIndexer, INamespaceTypeDefinition type)
 {
     noPiaIndexer?.Visit((ITypeDefinition)type);
 }
예제 #2
0
        /// <summary>
        /// Returns all top-level (not nested) types defined in the module.
        /// </summary>
        public override IEnumerable <INamespaceTypeDefinition> GetTopLevelTypes(EmitContext context)
        {
            TypeReferenceIndexer typeReferenceIndexer = null;
            HashSet <string>     names;

            // First time through, we need to collect emitted names of all top level types.
            if (_namesOfTopLevelTypes == null)
            {
                names = new HashSet <string>();
            }
            else
            {
                names = null;
            }

            // First time through, we need to push things through TypeReferenceIndexer
            // to make sure we collect all to be embedded NoPia types and members.
            if (EmbeddedTypesManagerOpt != null && !EmbeddedTypesManagerOpt.IsFrozen)
            {
                typeReferenceIndexer = new TypeReferenceIndexer(context);
                Debug.Assert(names != null);

                // Run this reference indexer on the assembly- and module-level attributes first.
                // We'll run it on all other types below.
                // The purpose is to trigger Translate on all types.
                this.Dispatch(typeReferenceIndexer);
            }

            AddTopLevelType(names, _rootModuleType);
            VisitTopLevelType(typeReferenceIndexer, _rootModuleType);
            yield return(_rootModuleType);

            foreach (var type in this.GetAnonymousTypes(context))
            {
                AddTopLevelType(names, type);
                VisitTopLevelType(typeReferenceIndexer, type);
                yield return(type);
            }

            foreach (var type in this.GetTopLevelTypesCore(context))
            {
                AddTopLevelType(names, type);
                VisitTopLevelType(typeReferenceIndexer, type);
                yield return(type);
            }

            var privateImpl = this.PrivateImplClass;

            if (privateImpl != null)
            {
                AddTopLevelType(names, privateImpl);
                VisitTopLevelType(typeReferenceIndexer, privateImpl);
                yield return(privateImpl);
            }

            if (EmbeddedTypesManagerOpt != null)
            {
                foreach (var embedded in EmbeddedTypesManagerOpt.GetTypes(context.Diagnostics, names))
                {
                    AddTopLevelType(names, embedded);
                    yield return(embedded);
                }
            }

            if (names != null)
            {
                Debug.Assert(_namesOfTopLevelTypes == null);
                _namesOfTopLevelTypes = names;
            }
        }