I have lots of classes reflecting my screen Repository from White/UIAutomation. To use repository I need to create lots of classes that reflect screens of my application windows.
To create a repository I use the following method:
var repoReport = repository.Get<MyClassRepresentingWindow>("WindowTitle",
InitializeOption.WithCache);
it passes a generic type which is a Class I prepared.
What I want to do is to create a Dictionary(stringClassName, string windowTitle) or any Map to pass to that method. The problem is can't pass className like in Java ClassForName.
I tried System.Activator
but without any success.
Object configObj = System.Activator.CreateInstance(c);
Type c = System.Type.GetType("Namespace.MyClassRepresentingWIndow");
var myClass = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance("Namespace.MyClassRepresentingWIndow");
Type type = assembly.GetType("Namespace.MyClassRepresentingWIndow");
object obj = Activator.CreateInstance(type);
var repoReport = repository.Get<c>("WindowTitle",
InitializeOption.WithCache);
var repoReport = repository.Get<c.Name>("WindowTitle",
InitializeOption.WithCache);
Update1 Guys, I'm not sitting in front of the code but I'll try to make my question less complicate.
This is a method which I found in the White repository that I think I use: https://github.com/petmongrels/white/blob/itemsmap/Components/Repository/Source/ScreenRepository.cs
public virtual T Get<T>(string title, InitializeOption option) where T : AppScreen
{
ClearClosedScreens();
AppScreen screen;
var repositoryCacheKey = new ScreenRepositoryCacheKey(title, typeof (T));
if (!screenCache.TryGetValue(repositoryCacheKey, out screen))
{
Window window = applicationSession.Application.GetWindow(title, IdentifiedOption<T>(option));
screen = GetScreen<T>(window);
screenCache.Add(repositoryCacheKey, screen);
}
if (screen != null)
sessionReport.Next(typeof (T));
return (T) screen;
}
As I remember VS displayed .Get as a .Get<"class" type>. I'm sorry I can't express myself better. Please have a patient with me because I'm not familiar with this terminology.
Update2
At the end I want to get something like this:
var repoReport1 = repository.Get<MyClassRepresentingWindow1>("WindowTitle", InitializeOption.WithCache);
var repoReport1 = repository.Get<MyClassRepresentingWindow2>("WindowTitle", InitializeOption.WithCache);
var repoReport1 = repository.Get<MyClassRepresentingWindow3>("WindowTitle", InitializeOption.WithCache);
And I have a code of MyClassRepresentingWindow{1,2,3}
. I just don't know how to pass class name to Get method. On input I have a string name of this class. On output I want to deliver something that this method .Get<T>
can get.
I hope you can understand me now.