1

I am given a RepoItemInfo object, and would like to retrieve the corresponding adapter from my repository.

RepoItemInfo.FindAdapter<T> finds or creates and adapter of type T, however my code is supposed to be general and should not assume a particular type. Instead, I would like to retrieve the adapter specified in my repository as denoted by RepoItemInfo.FullName.

1

I have found a solution via reflection.

public static class RanorexExtensions
{

    /// <summary>
    /// Creates an adapter for the associated repository item
    /// as defined in the repository.
    /// 
    /// If you know the adapter type, or want to use a different
    /// one, you can use <see cref="FindAdapter{T}" /> instead.
    /// </summary>
    /// <param name="itemInfo">The RepoItemInfo object</param>
    /// <returns>The adapter.</returns>
    public static Adapter GetAdapter(this RepoItemInfo itemInfo)
    {
        var folder = itemInfo.ParentFolder;
        Adapter adapter = (Adapter)folder.GetType().GetProperty(itemInfo.Name).GetValue(folder);
        return adapter;
    }
}
  • Hi! This solution has some disadvantages. In some cases .GetValue(folder) causes TIMEOUT – hellboy Jun 5 '18 at 10:37
  • Hi @hellboy sorry to hear. Worked fine for us. Is it reproducible? Can you conclude a certain pattern/common aspect of those that timeout and those that do not? – Richard Kiefer Sep 5 '18 at 13:57
0

you can do

repoItemInfo.CreateAdapter<WebElement>(true) 

if it is just for something like click

  • 2
    Could you explain a bit what the true parameter does? Thanks. Could I also use this approach if I do not now the type WebElement beforehand? – Richard Kiefer Aug 21 at 13:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.