How to get the name of the unknown item

Class library usage, coding and language questions.
AlexDozer
Posts: 33
Joined: Wed Sep 09, 2009 5:41 pm

How to get the name of the unknown item

Post by AlexDozer » Mon Oct 04, 2010 3:06 pm

Hello,

i want to check that all items, that I have in my repository, are available. If not, i want to log the name of the item that could not be found. But I don't know how to get the name which I have given the control in the repository.

Code: Select all

foreach (Unknown item in rep.CXX7.ToolBar.Self.Children)
{
    if (item.Valid)
        MessageBox.Show(item.ToString());
}
Could anyone help me?

Regards, Alex

AlexDozer
Posts: 33
Joined: Wed Sep 09, 2009 5:41 pm

Re: How to get the name of the unknown item

Post by AlexDozer » Tue Oct 05, 2010 7:39 am

Ok, I found out now that this way is wrong because I get not the items that are in the repository. Forget my example above.

New Question: How can I get all items of a folder in the repository? I need a possibility to go step by step through each item and folder in the repository. But how?

Regards, Alex

AlexDozer
Posts: 33
Joined: Wed Sep 09, 2009 5:41 pm

Re: How to get the name of the unknown item

Post by AlexDozer » Tue Oct 05, 2010 8:54 am

I found a way to solve the problem:

Code: Select all

PropertyInfo[] propertyInfos;
propertyInfos = typeof(RepositoryFolders.ToolBarFolder).GetProperties();

foreach (PropertyInfo info in propertyInfos)
    if (info.PropertyType == typeof(Ranorex.Button))
        MessageBox.Show(info.Name);

AlexDozer
Posts: 33
Joined: Wed Sep 09, 2009 5:41 pm

Re: How to get the name of the unknown item

Post by AlexDozer » Tue Oct 05, 2010 9:33 am

And here with casting to the wanted item.

Code: Select all

PropertyInfo[] propertyInfos;
propertyInfos = typeof(RepositoryFolders.ToolBarFolder).GetProperties();

foreach (PropertyInfo property in propertyInfos)
    if (property.PropertyType == typeof(Ranorex.Button))
    {
        Ranorex.Button button = (Ranorex.Button) property.GetGetMethod().Invoke(rep.CXX7.ToolBar, null);
                    
        if (button.Valid)
            Report.Info(property.Name, "Is valid");
        else
            Report.Warn(property.Name, "Is invalid");
     }