Best practices checking for objects in collections
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have some commands in which I add a button to the context menu in certain situations. Depending on the situation the button may be added or removed.
I'm alternating between using iterating through the definitions on the object they belong and if I have access to the it such as events that expose the commandbar object I iterate through it's buttons. If I don't I use a try/catch on the ControlDefinitions. Iterating through that causes an unacceptable pause.
I've always thought using exceptions to test objects is expensive but the delay breaks the users flow due to the pause.
What is the correct way to test for this?
I also run into this situation because I have different addins that add different sets of controls from a common set of dlls depending on the use context. Try/Catch works but is that the recommended way to test for things. I often need to test for the existance of things such as parameters (I have some plugins which will recreate sets of needed user parameters and some have hundreds if they don't exist already) and try/catch seems to be the best method.