示例#1
0
        /// <summary>
        ///     Read metadata from assembly.
        /// </summary>
        /// <param name="assembly">Assembly to read.</param>
        public MetadataInfo(Assembly assembly)
        {
            _module  = assembly.ManifestModule;
            Assembly = assembly;

            Stream assemblyStream;

            if (assembly.IsDynamic)
            {
                AssemblyGenerator generator = new AssemblyGenerator();
                byte[]            buffer    = generator.GenerateAssemblyBytes(assembly);
                assemblyStream = new MemoryStream(buffer);
            }
            else
            {
                assemblyStream = File.OpenRead(assembly.Location);
            }

            using PEReader peReader = new PEReader(assemblyStream);
            MetadataReader metadataReader = peReader.GetMetadataReader();

            Types = ReadTypes(metadataReader);

            assemblyStream.Dispose();
        }