I have a class and it has indexer. I would like to have a property named Item. This link tells how to rename the property name. So if I change the indexer name from Item to MyIndexer, is it going to be ok? Will WPF binding and other things of .NET work fine?
Asked
Active
Viewed 185 times
1
-
"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it **in the question itself**." – Jashaszun Jul 13 '15 at 16:17
-
1So long as nothing uses reflection to get a reference to the `Item` property directly expecting it to be an indexer, which can not be answered definitively. My guess is that WPF bindings and most other code will use either the indexer (`[]`) or enumerate the items, so the risk should be low. – D Stanley Jul 13 '15 at 16:18
-
Side note: collection (that's why you have indexer) which consists of single `Item` may be quite confusing entity... Make sure your class design makes sense for someone else than you. (possibly in your particular case it is ok, but that is not clear from the question). – Alexei Levenkov Jul 13 '15 at 17:11
-
I have moved the comment to be an answer. Glad you found it helpful. – Peter Duniho Jul 14 '15 at 03:23
1 Answers
1
Your question is impossible to answer precisely without more specifics. That said…
Indexer-aware code should be fine, but "WPF binding and other things" doesn't really narrow things down at all. So I cannot say whether the scenarios included in "WPF binding and other things" would be safe. You would need to provide some specific examples for that to be answerable.
Regardless, personally I would strongly advise against using the word "Item" as your property name; it is practically guaranteed that fewer potential problems exist from choosing a different name for the non-indexer property, than exist in deviating from the standard .NET convention on the indexer property name.

Peter Duniho
- 68,759
- 7
- 102
- 136