Page 1 of 1

How to get the name of the unknown item

Posted: Mon Oct 04, 2010 3:06 pm
by AlexDozer
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

Re: How to get the name of the unknown item

Posted: Tue Oct 05, 2010 7:39 am
by AlexDozer
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

Re: How to get the name of the unknown item

Posted: Tue Oct 05, 2010 8:54 am
by AlexDozer
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);

Re: How to get the name of the unknown item

Posted: Tue Oct 05, 2010 9:33 am
by AlexDozer
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");
     }