Open AlgorithmsAreCool opened 1 year ago
Looks like we're missing a codec for System.Collections.Generic.GenericEqualityComparer
, which is a type I am unfamiliar with.
I think the best way to handle these internal implementations of EqualityComparer<T>
is to treat them as the EqualityComparer<T>.Default
Eg:
GenericEqualityComparer<T>
ByteEqualityComparer
NullableEqualityComparer<T>
ObjectEqualityComparer<T>
EnumEqualityComparer<T>
We can do similarly for Comparer<T>
and its ilk.
I noticed does not affect the ImmutableDictionary
, which internally uses an EqualityComparer
, but it isn't respected by the surrogate. (copied code below for convenience)
The equality comparer affects the behavior of the Sorted* collections, but it also affects the behavior other keyed collections such as HashSet. It seems inconsistent that we try to preserve this behavior for some collections but not others (although pragmatically I understand why this was written this way).
[GenerateSerializer]
public struct ImmutableSortedDictionarySurrogate<TKey, TValue>
{
/// <summary>
/// Gets or sets the values.
/// </summary>
/// <value>The values.</value>
[Id(0)]
public List<KeyValuePair<TKey, TValue>> Values;
/// <summary>
/// Gets or sets the key comparer.
/// </summary>
/// <value>The key comparer.</value>
[Id(1)]
public IComparer<TKey> KeyComparer;
[Id(2)]
public IEqualityComparer<TValue> ValueComparer;
}
[GenerateSerializer]
public struct ImmutableDictionarySurrogate<TKey, TValue>
{
/// <summary>
/// Gets or sets the values.
/// </summary>
/// <value>The values.</value>
[Id(0)]
public Dictionary<TKey, TValue> Values;
}
If the surrogates set the comparer to null
when it's equivalent to the default for a given TKey
, that might suffice to maintain behavior.
I think the best way to handle these internal implementations of
EqualityComparer<T>
is to treat them as theEqualityComparer<T>.Default
Eg:
GenericEqualityComparer<T>
ByteEqualityComparer
NullableEqualityComparer<T>
ObjectEqualityComparer<T>
EnumEqualityComparer<T>
We can do similarly for
Comparer<T>
and its ilk.
Triage: we should do this ^
Hello, and thank you for all the amazing work on Orleans.
I have noticed that if you specify a record type as a type argument in a ImmutableSortedDictionary<,>, you get an exception.
Stacktrace
Repro