Page 1 of 1

Iterating elements in a repository

Posted: Wed Oct 05, 2016 10:57 am
by Makezu
I have a collection of repository elements in my repository neatly organized into different folders and with describing names. Now i'd like to iterate over these repository items and create a dictionary from them, with each item's name as the key and its RepoItemInfo as the value.

But can you do this in Ranorex? I'd like to be able to do this because I'm reading key-value pairs from a text file and if i'd be able to create a dictionary from my repository elements, I could supply the values for each element very easily, using the values from the text file that i read into memory.

So, something like this:

foreach (RepoItem item in formButtonsRepoFolder)
{
repoItemDict.add(item.Name, item.Info);
}

Re: Iterating elements in a repository

Posted: Thu Oct 06, 2016 12:08 pm
by Support Team
Hi Makezu,

You could try somthing like that:
//Create dictionary that holds repository items names and RepoItemInfo elements
        	Dictionary<string, RepoItemInfo> myDict = new Dictionary<string, RepoItemInfo>();
        	
        	//Sample folder which holds repo elements
        var anyFolderContainingRepoElements = repo.<Placeholder>.AnyFolder.SelfInfo.Children;
       
        //Add to dictionary
        foreach (RepoItemInfo element in anyFolderContainingRepoElements) 
        {
        	myDict.Add(element.Name, element);        	
        }
I hope this helps.

Sincerely,
Robert

Re: Iterating elements in a repository

Posted: Thu Oct 06, 2016 6:21 pm
by Makezu
Thanks for the answer Robert, so it is really that simple then, I missed the fact that you can query folder's children like that.

And just to clarify, this will return me only the elements that I have added to the repository and the names I've given them in the repository, not all of the children of that element as they appear in Ranorex Spy for example?

Re: Iterating elements in a repository

Posted: Fri Oct 07, 2016 7:48 am
by Support Team
Hi Makezu,

Exactly, only the repository elements are accessed.

Sincerely,
Robert