IEnumerable keys doesn't work
See original GitHub issueHi there! thanx for awesome project! It makes my unity development much easier 🎉
well, I’m trying to create GenericDictionary<string[], string>
in my project, however it doesn’t work - reffering to the key always returns KeyNotFound exception
.
Atm, I’m working it around by using this code:
foreach (var key in myDict.Keys)
if (key.SequenceEqual(query))
{
Debug.Log("query found");
}
but it would be nice to have it in the package
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
c# - Getting Keys and Values from IEnumerable<Dictionary ...
Try with: IEnumerable<object> values = testData.SelectMany(x => x.Values);.
Read more >Binding to non-null IEnumerable doesn't work · Issue #36390
I've checked this on both empty and not empty initialized IEnumerable<T> s and it seems to work, all tests are also passed. If...
Read more >C#: IEnumerable, yield return, and lazy evaluation
IEnumerable is the return type from an iterator. An iterator is a method that uses the yield return keywords. yield return is different...
Read more >IEnumerable<T> Interface (System.Collections.Generic)
Enumerates and transforms a sequence, and produces an immutable dictionary of its contents by using the specified key and value comparers. ToImmutableHashSet< ...
Read more >Enumerable.ToDictionary Method (System.Linq)
Creates a Dictionary<TKey,TValue> from an IEnumerable<T> according to a specified key selector function, a comparer, and an element selector function.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Quick follow up.
I’ve found that it’s quite easy to check if the key is enumerable (serializedProperty.isArray) - but this flag is true for strings, so I’m wary that there are other properties that behave this way.
Currently the best solution for having enumerable keys would probably be to create a class and override the Equals and GetHashCode methods to get the desired behavior. This way the user can choose, with the drawback of added ceremony whenever enumerable keys with value based comparisons are desired.
I’ll be digging a bit deeper though so will leave this issue opened.
I tested this out some more and see what you mean, looking in the inspector it seems logical that enumerable keys should be value based rather than reference based (notice there’s no warning about duplicate keys):
I’m not sure if there are edge cases where you do want reference based enumerable types though so I’m investigating this closer.
Regardless it seems the dictionary key lookup would go from ~O(1) to O(N) when using enumerable key types, but I suppose there’s no way around that?