question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IEnumerable keys doesn't work

See original GitHub issue

Hi 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:open
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
upscalebabycommented, Apr 18, 2022

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.

0reactions
upscalebabycommented, Apr 4, 2022

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):

image

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found