title: How to pass className to a method which gets generic type as a parameter in C#
body: <p>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.</p>
  
  <p>To create a repository I use the following method:</p>
  
  <pre><code>var repoReport = repository.Get&lt;MyClassRepresentingWindow&gt;("WindowTitle", 
  InitializeOption.WithCache);
  </code></pre>
  
  <p>it passes a generic type which is a Class I prepared.</p>
  
  <p>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.</p>
  
  <p>I tried <code>System.Activator</code>  but without any success.</p>
  
  <pre><code>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&lt;c&gt;("WindowTitle", 
  InitializeOption.WithCache);
  
  var repoReport = repository.Get&lt;c.Name&gt;("WindowTitle", 
  InitializeOption.WithCache);
  </code></pre>
  
  <p><strong>Update1</strong>
  Guys, I'm not sitting in front of the code but I'll try to make my question less complicate.</p>
  
  <p>This is a method which I found in the White repository that I think I use:
  <a href="https://github.com/petmongrels/white/blob/itemsmap/Components/Repository/Source/ScreenRepository.cs" rel="nofollow">https://github.com/petmongrels/white/blob/itemsmap/Components/Repository/Source/ScreenRepository.cs</a></p>
  
  <pre><code>public virtual T Get&lt;T&gt;(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&lt;T&gt;(option));
              screen = GetScreen&lt;T&gt;(window);
              screenCache.Add(repositoryCacheKey, screen);
          }
  
          if (screen != null)
              sessionReport.Next(typeof (T));
          return (T) screen;
      }
  </code></pre>
  
  <p>As I remember VS displayed .Get as a .Get&lt;"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.</p>
  
  <p><strong>Update2</strong></p>
  
  <p>At the end I want to get something like this:</p>
  
  <pre><code>var repoReport1 = repository.Get&lt;MyClassRepresentingWindow1&gt;("WindowTitle", InitializeOption.WithCache);
  var repoReport1 = repository.Get&lt;MyClassRepresentingWindow2&gt;("WindowTitle", InitializeOption.WithCache);
  var repoReport1 = repository.Get&lt;MyClassRepresentingWindow3&gt;("WindowTitle", InitializeOption.WithCache);
  </code></pre>
  
  <p>And I have a code of <code>MyClassRepresentingWindow{1,2,3}</code>. 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 <code>.Get&lt;T&gt;</code> can get.
  I hope you can understand me now.</p>