Exemplo n.º 1
0
        public async Task Populate()
        {
            this.IsMefAssembly    = true;
            this.fullAssemblyName = this.metadataReader.GetFullAssemblyName();

            this.knownExportAttributeOrDerivedType = new HashSet <string>()
            {
                "System.ComponentModel.Composition.ExportAttribute",
                "System.ComponentModel.Composition.InheritedExportAttribute"
            };
            this.knownImportAttributeOrDerivedType = new HashSet <string>()
            {
                "System.ComponentModel.Composition.ImportAttribute",
                "System.ComponentModel.Composition.ImportManyAttribute"
            };

            var referenceFullNames = metadataReader.GetReferenceAssemblyFullNames();
            var tasks = new List <Task <AssemblyCatalogInfo> >();

            foreach (var referenceAssemblyFullName in referenceFullNames)
            {
                var referenceCatalog = this.discovery.GetAssemblyCatalogInfoFromAssemblyName(referenceAssemblyFullName);
                if (referenceCatalog != null)
                {
                    tasks.Add(referenceCatalog);
                }
            }

            foreach (var task in tasks)
            {
                var referenceCatalog = await task.ConfigureAwait(false);

                if (referenceCatalog == null)
                {
                    continue;
                }

                var knownExportAttributes = referenceCatalog.KnownExportOrDerived;
                foreach (var known in knownExportAttributes)
                {
                    knownExportAttributeOrDerivedType.Add(known);
                }

                var knownImportAttributes = referenceCatalog.KnownImportOrDerived;
                foreach (var known in knownImportAttributes)
                {
                    knownImportAttributeOrDerivedType.Add(known);
                }
            }

            foreach (var typeHandle in metadataReader.TypeDefinitions)
            {
                var typeDefinition = metadataReader.GetTypeDefinition(typeHandle);
                Walk(typeDefinition);
            }

            foreach (var customAttributeHandle in metadataReader.CustomAttributes)
            {
                var customAttribute     = metadataReader.GetCustomAttribute(customAttributeHandle);
                var attributeTypeHandle = metadataReader.GetAttributeTypeHandle(customAttribute);

                if (TryHandleImportAttribute(customAttribute, attributeTypeHandle))
                {
                    continue;
                }

                if (TryHandleExportAttribute(customAttribute, attributeTypeHandle))
                {
                    continue;
                }
            }
        }