コード例 #1
0
        private IReadOnlyList <AssemblyMetadata> GetReferenceAssemblies()
        {
            var assemblies = new List <AssemblyMetadata>(1024);

            var assembliesVisited = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase);

            var referenceModulesToProcess = new Stack <(AssemblyMetadata Parent, AssemblyReferenceWrapper AssemblyReference)>(MainAssemblyMetadata.AssemblyReferences.Select(x => (MainModule: MainAssemblyMetadata, x)));

            while (referenceModulesToProcess.Count > 0)
            {
                var(parent, current) = referenceModulesToProcess.Pop();
                if (assembliesVisited.Contains(current.Name))
                {
                    continue;
                }

                assembliesVisited.Add(current.Name);

                var assemblyMetadata = AssemblyLoadingHelper.ResolveCompilationModule(current.Name, parent, current.Version, current.IsWindowsRuntime, current.IsRetargetable, current.PublicKey);

                if (assemblyMetadata is null)
                {
                    continue;
                }

                assemblies.Add(assemblyMetadata);

                foreach (var child in assemblyMetadata.AssemblyReferences)
                {
                    referenceModulesToProcess.Push((assemblyMetadata, child));
                }
            }

            return(assemblies);
        }
コード例 #2
0
        /// <summary>
        /// Gets the MetadataRepository module for the specified name.
        /// </summary>
        /// <param name="name">The name to fetch.</param>
        /// <param name="parent">The parent of the MetadataRepository module.</param>
        /// <param name="version">The version to fetch for.</param>
        /// <param name="isWindowsRuntime">If the assembly is a windows runtime.</param>
        /// <param name="isRetargetable">If the assembly can be targeting another assembly.</param>
        /// <param name="publicKey">The optional public key.</param>
        /// <returns>The MetadataRepository module.</returns>
        public static AssemblyMetadata?GetAssemblyMetadataForName(string name, AssemblyMetadata parent, Version?version = null, bool isWindowsRuntime = false, bool isRetargetable = false, string?publicKey = null)
        {
            if (parent is null)
            {
                throw new ArgumentNullException(nameof(parent));
            }

            return(AssemblyLoadingHelper.ResolveCompilationModule(name, parent, version, isWindowsRuntime, isRetargetable, publicKey));
        }