Exemple #1
0
 private static void AddReferencedAssemblyInfo(AssemblyMetadataParser parser, AssemblyMetaDataInfo result)
 {
     try
     {
         // ToArray is required, otherwise sequence might be enumerated when context is already closed.
         var referencedAssemblyNames = parser.GetReferencedAssemblyNames().ToArray();
         result.SetReferencedAssemblyNames(referencedAssemblyNames);
     }
     catch
     {
         // Ignore if unable to fetch information.
     }
 }
Exemple #2
0
        private static void AddAssemblyAttributes(AssemblyMetadataParser parser, AssemblyMetaDataInfo result)
        {
            try
            {
                foreach (var attribute in parser.GetAssemblyAttributes())
                {
                    var value = TryReadAttributeValue(attribute);
                    if (value == null)
                    {
                        continue;
                    }

                    var displayName = ReadAttributeDisplayName(attribute);
                    result.AddMetadata(displayName, value);
                }
            }
            catch (Exception)
            {
                // Silently abort the process if unable to fetch all the attributes.
            }
        }
Exemple #3
0
        public static AssemblyMetaDataInfo?ReadMetaData(string assemblyPath)
        {
            if (string.IsNullOrWhiteSpace(assemblyPath))
            {
                return(null);
            }

            var assemblyName = AssemblyName.GetAssemblyName(assemblyPath);

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

            var result = new AssemblyMetaDataInfo(assemblyName);

            // For WinRT component, we can only read Full Name.
            if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
            {
                return(result);
            }

            try
            {
                using var metadataParser = new AssemblyMetadataParser(assemblyPath);
                AddAssemblyAttributes(metadataParser, result);
                AddReferencedAssemblyInfo(metadataParser, result);
                result.DebugData = metadataParser.GetDebugData();
            }
            catch
            {
                // Ingore if unable to read metadata.
            }

            return(result);
        }