Validate.Exists output type

Class library usage, coding and language questions.
aturner
Posts: 5
Joined: Wed Oct 01, 2014 5:02 pm

Validate.Exists output type

Post by aturner » Wed Oct 01, 2014 6:01 pm

Disclaimer: I am new at C# and code modules.

I would like to test that a repository exists and branch conditionally depending upon the result. I have a variable added to the module named varShipExists, but I don't know how to assign a value to that variable from the validate class.

Validate.Exists(repo.MainForm.ElementHost1.WPF_Ship_ViaInfo);

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Validate.Exists output type

Post by krstcs » Thu Oct 02, 2014 6:30 pm

Edit to add: First, let me say "Welcome!" Ask lots of questions and try lots of stuff. This forum is full of people who have had the same problems that you will likely face and we are all glad to help!



Only use the Validate class for Validations. That is, only use Validate when you actually need to report that something is what you expect it to be.

Use the ".Exists()" method of the RepoItemInfo class when you need to do logical comparisons for the existence of an element:

Code: Select all

if (repo.MainForm.ElementHost1.WPF_Ship_ViaInfo.Exists()) {
  //do stuff here...
}
Shortcuts usually aren't...

User avatar
Support Team
Site Admin
Site Admin
Posts: 11710
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Validate.Exists output type

Post by Support Team » Fri Oct 03, 2014 2:50 pm

Hi krstcs and aturner,

Thanks krstcs for your answer this is very much appreciated :)!

For the sake of completeness I just want to mention that it is also possible to use a Validate.Exists method which doesn't throw an exception when the element cannot be found.
There are different overloads for the Validate.Exists method and there are also some which allow you to specify if an exception should be thrown or not.
To have a look at the available overloads please take a look at our online API: Exists Method.

Regards,
Markus
.
Image