You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm reporting this as a bug, though it seems too obvious to have been overlooked. If it's not a bug, I'm curious about the rationale behind ToFrozenDictionary() not adopting the IEqualityComparer from the source Dictionary.
Reproduction Steps
// Note the case insensitive IEqualityComparer<T> - StringComparer.OrdinalIgnoreCase here.
var dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { ["a"] = 1 };
// Assertions will pass
var frozenDictionary = dictionary.ToFrozenDictionary( StringComparer.OrdinalIgnoreCase);
Debug.Assert(frozenDictionary.Comparer == dictionary.Comparer);
Debug.Assert(frozenDictionary.TryGetValue("A", out int _));
// Assertions will fail
frozenDictionary = dictionary.ToFrozenDictionary( /* No StringComparer */);
Debug.Assert(frozenDictionary.Comparer == dictionary.Comparer);
Debug.Assert(frozenDictionary.TryGetValue("A", out int _));
Expected behavior
I expect the following would satisfy the assertion.
var dictionary = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase) { ["a"] = 1 };
var frozenDictionary = dictionary.ToFrozenDictionary();
Debug.Assert(frozenDictionary.Comparer == dictionary.Comparer);
Debug.Assert(frozenDictionary.TryGetValue("A", out int _));
Actual behavior
The actual behavior is that the assertions fail for the expected behavior above.
Regression?
No response
Known Workarounds
Explicitly pass the same IEqualityComparer to ToFrozenDictionary(comparer) as you do when instantiating a dictionary it will be called on. This is a very simple workaround. However, there are times where I would not necessarily know the IEqualityComparer of the source dictionary. Serialization/Deserialization comes to mind.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered:
ToXxDictionary series methods don't operate on a dictionary, they operate on collection of key-value pairs. Thus no concept of comparer will be passed implicitly.
Description
I'm reporting this as a bug, though it seems too obvious to have been overlooked. If it's not a bug, I'm curious about the rationale behind ToFrozenDictionary() not adopting the IEqualityComparer from the source Dictionary.
Reproduction Steps
Expected behavior
I expect the following would satisfy the assertion.
Actual behavior
The actual behavior is that the assertions fail for the expected behavior above.
Regression?
No response
Known Workarounds
Explicitly pass the same IEqualityComparer to ToFrozenDictionary(comparer) as you do when instantiating a dictionary it will be called on. This is a very simple workaround. However, there are times where I would not necessarily know the IEqualityComparer of the source dictionary. Serialization/Deserialization comes to mind.
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: