[C#] Support Dictionary Comparer/Comparator Serialization
Feature Request
Support Dictionary Comparer/Comparator Serialization.
Is your feature request related to a problem? Please describe
No response
Describe the solution you'd like
Support Dictionary Comparer/Comparator Serialization can be implemented, but if it's a delegate, how to serialize delegate is still an issue
Describe alternatives you've considered
No response
Additional context
No response
@chaokunyang Please assign this to me.
Hi @miantalha45 , I think it's better to finish exising taken issues before taking more so we can move faster.
Hi @chaokunyang I only have a single assigned issue on which i am working and ready to submit a PR. For all other assigned issue, i have created PRs that are under review.
@miantalha45 Assigned to you. But this is a little complicated, the Comparer/Comparator is a delegate and I'm not sure whether there is a reliable approach to serialize it. You may need to do some research.
ok @chaokunyang I will start researching how (and if) this kind of delegate-based comparator can be reliably serialized, and look into approaches used in similar cases. I will update here once I have more clarity or a potential direction.
Hi @chaokunyang
I looked into the delegate concern around Dictionary<K,V>.Comparer. It turns out it’s not a delegate, it’s an IEqualityComparer
My thinking is to handle it in a few simple cases:
If it is the default comparer (EqualityComparer
For well-known StringComparer singletons (e.g., Ordinal, OrdinalIgnoreCase), we can write a flag + small ID and recreate them on read.
For custom comparer classes, we serialize them as normal objects via Fory’s type resolver (assuming the type is registered).
If the comparer is compiler-generated or wraps a delegate, we reject it with a clear NotSupportedException.
In cross-language mode, I would skip comparer serialization entirely since it’s runtime-specific.
Let me know if this sounds reasonable or if you would prefer limiting support further.