0

库加载,我可以在调试器中查看 ziparchiveentries,但我无法通过反射访问 ziparchiveentry 对象数组的方法或属性:

Assembly CompressionLib = Assembly.LoadWithPartialName("System.IO.Compression");
Module CompressionModule = CompressionLib.GetModule("System.IO.Compression.dll");
Type ZipArchiveType = CompressionModule.GetType("System.IO.Compression.ZipArchive");
Type ZipArchiveEntryType = CompressionModule.GetType("System.IO.Compression.ZipArchiveEntry");
ConstructorInfo UnzipConstructor = ZipArchiveType.GetConstructor(new[] { typeof(System.IO.Stream) });
object UnzipInstance = UnzipConstructor.Invoke(new object[] Plugin.PluginFiles[0].fileData });
MethodInfo UnzipGetEntries = ZipArchiveType.GetMethod("get_Entries");
ICollection UnzippableFilesCollection = (ICollection)UnzipGetEntries.Invoke(UnzipInstance, null);
object[] UnzippableFiles = new ArrayList(UnzippableFilesCollection).ToArray();

此时我可以在调试器中查看,例如:

UnzippableFiles[25]
{pt-br/ACResources.resources.dll}
    Archive: {System.IO.Compression.ZipArchive}
    CompressedLength: 78659
    ExternalAttributes: -2119958528
    FullName: "pt-br/ACResources.resources.dll"
    LastWriteTime: {1/8/2019 7:29:04 AM -08:00}
    Length: 232696
    Name: "ACResources.resources.dll"

然而例子:

ZipArchiveEntryType.GetType().GetProperty("FullName").GetValue(UnzippableFiles[25])

返回错误:

    `'ZipArchiveEntryType.GetType().GetProperty("FullName").GetValue(UnzippableFiles[25])' threw an exception of type 'System.Reflection.TargetException'`
Message: "Object does not match target type."
4

1 回答 1

0

我设法通过删除上下文中未解决的 GetType() 来获得它:

ZipArchiveEntryType.GetProperty("FullName").GetValue(new ArrayList((ICollection)ZipArchiveType.GetProperty("Entries").GetValue(UnzipInstance)).ToArray()[11])
于 2019-01-09T00:14:50.307 回答