Iterating elements in a repository

Class library usage, coding and language questions.
Makezu
Posts: 2
Joined: Wed Oct 05, 2016 10:48 am

Iterating elements in a repository

Post by Makezu » Wed Oct 05, 2016 10:57 am

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);
}

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

Re: Iterating elements in a repository

Post by Support Team » Thu Oct 06, 2016 12:08 pm

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
.
Image

Makezu
Posts: 2
Joined: Wed Oct 05, 2016 10:48 am

Re: Iterating elements in a repository

Post by Makezu » Thu Oct 06, 2016 6:21 pm

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?

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

Re: Iterating elements in a repository

Post by Support Team » Fri Oct 07, 2016 7:48 am

Hi Makezu,

Exactly, only the repository elements are accessed.

Sincerely,
Robert
.
Image