Nig*_*888 5 .net c# xamarin.ios .net-standard
我们目前使用EqualityComparer<TKey>.Default默认方式来初始化通用字典。但是,当字典的键为 type 时,它会在 Xamarin.iOS 上崩溃并出现以下错误int(但在我尝试过的许多其他平台上都有效):
Lucene.Net.Support.LurchTable2<Lucene.Net.Facet.Taxonomy.FacetLabel, Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>:InternalInsert<Lucene.Net.Support.LurchTable2/Add2Info<Lucene.Net.Facet.Taxonomy.FacetLabel, Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>> (int,Lucene.Net.Facet.Taxonomy.FacetLabel,int&,Lucene.Net.Support.LurchTable/Add2Info<Lucene.Net.Facet.Taxonomy.FacetLabel, Lucene.Net.Facet.Taxonomy.Directory.DirectoryTaxonomyReader/Int32Class>)在仅 aot 模式下运行时尝试 JIT 编译方法。有关更多信息,请参阅https://developer.xamarin.com/guides/ios/advanced_topics/limitations/ 。at Lucene.Net.Support.LurchTable2[TKey,TValue].Insert[T] (TKey key, T& value) <0x2570f48 + 0x000e0> in <063e095c95d945a4ace32ab83d1227eb#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 at (包装未知)系统.Object.gsharedvt_in()在 Lucene.Net.Support.LurchTable2[TKey,TValue].AddOrUpdate (TKey key, TValue addValue, Lucene.Net.Support.KeyValueUpdate2[TKey,TValue] fnUpdate) <0x232824c + 0x0013b> 在 <063e095c95d945a4ace32ab83d1227eb#2ae0fea9ea4eacaef83 bf2e9713bb8ea>:0 在Lucene.Net.Facet.Taxonomy.LRUHashMap2[TKey,TValue].Put (TKey key, TValue value) <0x2c487f8 + 0x0015b> in <79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 在 Lucene.Net .Facet.Taxonomy.Directory.DirectoryTaxonomyReader.GetOrdinal (Lucene.Net.Facet.Taxonomy.FacetLabel cp) <0x2c51970 + 0x0019b> 在 <79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 位于 Lucene.Net.Facet.Taxonomy.Int32Taxonomy Facets.GetTopChildren(System.Int32 topN,System.String dim,System.字符串[]路径)<0x2c481dc + 0x0008f>在<79d3a7b905954d0993025c09c5d087ce#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0在Login.MyMB.Lucene.Client.LuceneArticoliSearcher.GetListaArticoloXRicercaAvanzataConRicercaSempl冰 (System.Collections.Generic.List1[T] listParametri) <0x224add0 + 0x001bb> in < 8f49891e0f0546e185aba7424d294ef7#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 在 Login.MyMB.Lucene.Client.LuceneArticoliSearcher.GetListaArticoloConRicercaSemplice (System.Collections.Generic.List1[T] listParametri) <0x224afbc + 0x0 009f> 在 <8f49891e0f0546e185aba7424d294ef7#2ae0fea9ea4eacaef83bf2e9713bb8ea>:0 在 MyMB.Forms.RicercaLucene .RicercaArticoloLucene.GetListaArticoliXRicercaSemplice (Login.MyMB.Interface.IAmbiente 环境、Login.MyMB.Lucene.Client.LuceneArticoliSearcher las、System.Collections.Generic.List`1[T] ListParametri、System.Boolean isAbilitataRicercaBarcode) <0xe47fc0 + 0x000e7> 中:0 ................................
在链接https://learn.microsoft.com/it-it/xamarin/ios/internals/limitations,我找到了问题原因(我想......):
值类型作为字典键使用值类型作为
Dictionary<TKey, TValue>键是有问题的,因为默认的字典构造函数尝试使用EqualityComparer<TKey>.Default.EqualityComparer<TKey>.Default反过来,尝试使用反射来实例化实现该IEqualityComparer<TKey>接口的新类型。这适用于引用类型(因为跳过了反射+创建新类型步骤),但对于值类型,一旦您尝试在设备上使用它,它就会很快崩溃并烧毁。 解决方法:手动实现新类型中的接口并向( ) 构造IEqualityComparer<TKey>函数提供该类型的实例。Dictionary<TKey, TValue>IEqualityComparer<TKey>
是否有内置的跨平台方法来创建默认值IEqualityComparer<int>?我试图避免开设这样的课程
private class Int32EqualityComparer : IEqualityComparer<int>
{
bool IEqualityComparer<int>.Equals(int x, int y)
{
return x.Equals(y);
}
int IEqualityComparer<int>.GetHashCode(int obj)
{
return obj.GetHashCode();
}
}
Run Code Online (Sandbox Code Playgroud)
只是为了解决这个错误。