From a7a5c413709fbeec823ec1f6618f9cc67f1356a2 Mon Sep 17 00:00:00 2001 From: itn3000 Date: Wed, 21 Dec 2022 10:37:12 +0900 Subject: [PATCH] replace Activator.CreateInstance to Func for avoiding error in NativeAOT --- .../Compressors/Xz/Filters/BlockFilter.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs index ecfe7ae0..20b8b286 100644 --- a/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs +++ b/src/SharpCompress/Compressors/Xz/Filters/BlockFilter.cs @@ -19,18 +19,18 @@ public abstract class BlockFilter : ReadOnlyStream LZMA2 = 0x21 } - private static readonly Dictionary FilterMap = new Dictionary< + private static readonly Dictionary> FilterMap = new Dictionary< FilterTypes, Type > { - { FilterTypes.ARCH_x86_FILTER, typeof(X86Filter) }, - { FilterTypes.ARCH_PowerPC_FILTER, typeof(PowerPCFilter) }, - { FilterTypes.ARCH_IA64_FILTER, typeof(IA64Filter) }, - { FilterTypes.ARCH_ARM_FILTER, typeof(ArmFilter) }, - { FilterTypes.ARCH_ARMTHUMB_FILTER, typeof(ArmThumbFilter) }, - { FilterTypes.ARCH_SPARC_FILTER, typeof(SparcFilter) }, - { FilterTypes.LZMA2, typeof(Lzma2Filter) } + { FilterTypes.ARCH_x86_FILTER, () => new X86Filter() }, + { FilterTypes.ARCH_PowerPC_FILTER, () => new PowerPCFilter() }, + { FilterTypes.ARCH_IA64_FILTER, () => new IA64Filter() }, + { FilterTypes.ARCH_ARM_FILTER, () => new ArmFilter() }, + { FilterTypes.ARCH_ARMTHUMB_FILTER, () => new ArmThumbFilter() }, + { FilterTypes.ARCH_SPARC_FILTER, () => new SparcFilter() }, + { FilterTypes.LZMA2, () => new Lzma2Filter() } }; public abstract bool AllowAsLast { get; } @@ -48,7 +48,7 @@ public abstract class BlockFilter : ReadOnlyStream throw new NotImplementedException($"Filter {filterType} has not yet been implemented"); } - var filter = (BlockFilter)Activator.CreateInstance(FilterMap[filterType])!; + var filter = FilterMap[filterType]()!; var sizeOfProperties = reader.ReadXZInteger(); if (sizeOfProperties > int.MaxValue)