kalldrexx
13 years agoContributor
How do I determine if a property exists on an object in c#?
I cannot seem to find a way to determine if a property exists or not. For example, some of the checkboxes in our Delphi application contain ValueChecked and ValueUnChecked properties, which determines the string value when the checkbox is checked or unchecked. I currently get these properties via
The problem is that not all checkboxes use these properties, and the ones that don't do not have these properties defined at all. So when this method is called in my code (generic method to handle setting the state of a checkbox) I get an error because TestComplete stalls waiting for the "ValueChecked" property, and when it's not found and times out it returns an object that can't be casted.
I need a way to instantly check if a property exists on an object so I can take an alternative action in those cases. Even if my current method would work (I just have to check if the returned object's Exist property is true or false) it does not work for my case because the property check still has to wait until the timeout period before it determines that the property doesn't exist.
I tried to find a Wait* method I could use (similar to WaitAliasChild) but all I could find was WaitProperty. However, that waits until the property is set to a specific value, and since I cannot predict what value the ValueChecked will be set to (in fact this code is meant to find that out) this does not work for me. I also tried using the componentObj.PropertyExists(Name), but this seems to fail as well as the VCLObject doesn't have the PropertyExists method.
How can I efficiently and quickly determine if an object has a specific property?
valueChecked = (string)checkbox["ValueChecked"];
valueUnChecked = (string)checkbox["ValueUnChecked"];
The problem is that not all checkboxes use these properties, and the ones that don't do not have these properties defined at all. So when this method is called in my code (generic method to handle setting the state of a checkbox) I get an error because TestComplete stalls waiting for the "ValueChecked" property, and when it's not found and times out it returns an object that can't be casted.
I need a way to instantly check if a property exists on an object so I can take an alternative action in those cases. Even if my current method would work (I just have to check if the returned object's Exist property is true or false) it does not work for my case because the property check still has to wait until the timeout period before it determines that the property doesn't exist.
I tried to find a Wait* method I could use (similar to WaitAliasChild) but all I could find was WaitProperty. However, that waits until the property is set to a specific value, and since I cannot predict what value the ValueChecked will be set to (in fact this code is meant to find that out) this does not work for me. I also tried using the componentObj.PropertyExists(Name), but this seems to fail as well as the VCLObject doesn't have the PropertyExists method.
How can I efficiently and quickly determine if an object has a specific property?