コード例 #1
0
        /// <summary>
        /// Obtains identity of the specified .NET assembly.
        /// File must be a .NET assembly.
        /// Returns null if identity could not be obtained.
        /// </summary>
        /// <param name="path">The name of the file from which the identity is to be obtained.</param>
        /// <returns>The assembly identity of the specified file.</returns>
        public static AssemblyIdentity FromManagedAssembly(string path)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            // NOTE: We're not using System.Reflection.AssemblyName class here because we need ProcessorArchitecture
            using (MetadataReader r = MetadataReader.Create(path))
            {
                AssemblyIdentity identity = null;
                if (r != null)
                {
                    try
                    {
                        identity = new AssemblyIdentity(r.Name, r.Version, r.PublicKeyToken, r.Culture, r.ProcessorArchitecture);
                    }
                    catch (ArgumentException e)
                    {
                        if (e.HResult != unchecked ((int)0x80070057))
                        {
                            throw;
                        }
                        // 0x80070057 - "Value does not fall within the expected range." is returned from
                        // GetAssemblyIdentityFromFile for WinMD components
                    }
                }
                return(identity);
            }
        }
コード例 #2
0
ファイル: PathUtil.cs プロジェクト: Hellochaos/chaos-playfab
 public static bool IsManagedAssembly(string path)
 {
     if (String.IsNullOrEmpty(path))
     {
         throw new ArgumentNullException(nameof(path));
     }
     using (MetadataReader r = MetadataReader.Create(path))
         return(r != null);
 }
コード例 #3
0
 public AssemblyAttributeFlags(string path)
 {
     using (MetadataReader r = MetadataReader.Create(path))
         if (r != null)
         {
             IsSigned = !String.IsNullOrEmpty(r.PublicKeyToken);
             HasAllowPartiallyTrustedCallersAttribute = r.HasAssemblyAttribute("System.Security.AllowPartiallyTrustedCallersAttribute");
             HasSecurityTransparentAttribute          = r.HasAssemblyAttribute("System.Security.SecurityTransparentAttribute");
             HasPrimaryInteropAssemblyAttribute       = r.HasAssemblyAttribute("System.Runtime.InteropServices.PrimaryInteropAssemblyAttribute");
             HasImportedFromTypeLibAttribute          = r.HasAssemblyAttribute("System.Runtime.InteropServices.ImportedFromTypeLibAttribute");
             HasSecurityRulesAttribute = r.HasAssemblyAttribute("System.Security.SecurityRulesAttribute");
         }
 }
コード例 #4
0
 public static AssemblyIdentity FromManagedAssembly(string path)
 {
     if (!File.Exists(path))
     {
         return(null);
     }
     using (MetadataReader reader = MetadataReader.Create(path))
     {
         if (reader != null)
         {
             return(new AssemblyIdentity(reader.Name, reader.Version, reader.PublicKeyToken, reader.Culture, reader.ProcessorArchitecture));
         }
         return(null);
     }
 }