Exemple #1
0
        public AssemblyMetaData GetAssemblyMetadata(string assemblyPath)
        {
            var data = new AssemblyMetaData();

            var assemblyName = AssemblyName.GetAssemblyName(assemblyPath);

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

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

            var assembly = Assembly.Load(assemblyName);

            if (assembly != null)
            {
                data.SetFullName(assembly.FullName);

                try
                {
                    foreach (var attribute in assembly.GetCustomAttributesData())
                    {
                        if (attribute.ConstructorArguments.Count != 1 ||
                            attribute.ConstructorArguments[0].ArgumentType != typeof(string))
                        {
                            continue;
                        }

                        string typeName = attribute.Constructor.DeclaringType.Name;
                        if (typeName == "InternalsVisibleToAttribute")
                        {
                            continue;
                        }

                        string key = typeName.EndsWith("Attribute", StringComparison.OrdinalIgnoreCase)
                            ? typeName.Substring(0, typeName.Length - 9)
                            : typeName;

                        string value = attribute.ConstructorArguments[0].Value.ToString();

                        if (!String.IsNullOrEmpty(value))
                        {
                            data[key] = value;
                        }
                    }
                }
                catch (Exception)
                {
                    // if an exception occurs when loading custom attributes, just ignore
                }
            }

            return(data);
        }
Exemple #2
0
        public static AssemblyMetaData GetAssemblyMetadata(string assemblyPath)
        {
            if (!File.Exists(assemblyPath))
            {
                return(null);
            }

            AssemblyMetaData result = null;

            ExecuteRemotely(worker => result = worker.GetAssemblyMetadata(assemblyPath));
            return(result);
        }