Ejemplo n.º 1
0
        public static void SaveToFile(string filePath, AsmIndexResponse rootTokenName)
        {
            if (rootTokenName?.Asms == null || !rootTokenName.Asms.Any())
            {
                return;
            }
            var json = JsonConvert.SerializeObject(rootTokenName, Formatting.None,
                                                   new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            });

            File.WriteAllText(filePath, json);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a lookup going from Type name to Owning Assembly Index to Assembly Name to Assembly path
        /// </summary>
        /// <param name="binFolders">
        /// The \bin folder(s) containing all the various assemblies
        /// </param>
        /// <param name="asmIndexResponse">
        /// The loaded Assembly Index response typically loaded form file
        /// </param>
        /// <param name="tokenType">
        /// The token type found elsewhere typically by loading the TokenTypeResponse from file
        /// </param>
        /// <returns>
        /// The full path to the assembly which defines the given type
        /// </returns>
        public static string GetAssemblyPathFromRoot(
            AsmIndexResponse asmIndexResponse,
            MetadataTokenType tokenType,
            params string[] binFolders)
        {
            if (binFolders.Length <= 0 ||
                asmIndexResponse == null ||
                tokenType == null)
            {
                return(null);
            }

            //from index to full assembly name
            var assemblyIdx = asmIndexResponse.Asms.FirstOrDefault(a => a.IndexId == tokenType.OwnAsmIdx);

            if (assemblyIdx == null)
            {
                return(null);
            }

            var assemblyName = new AssemblyName(assemblyIdx.AssemblyName);

            foreach (var binFolder in binFolders)
            {
                if (string.IsNullOrWhiteSpace(binFolder) || !Directory.Exists(binFolder))
                {
                    continue;
                }
                var di = new DirectoryInfo(binFolder);
                foreach (var d in di.EnumerateFileSystemInfos())
                {
                    if (!new[] { ".dll", ".exe" }.Contains(d.Extension))
                    {
                        continue;
                    }
                    var dAsmName = AssemblyName.GetAssemblyName(d.FullName);

                    if (AssemblyName.ReferenceMatchesDefinition(dAsmName, assemblyName))
                    {
                        return(d.FullName);
                    }
                }
            }

            return(null);
        }