title: How to create instances of type declarations?
body: <p>I want to store a class declaration in a struct and later instantiate new objects from that class but I'm running into a few obstacles. I know how to do this in a few other languages but in C# I didn't have any success yet.</p>
  
  <pre><code>abstract class Command
  {
      // Base class for all concrete command classes.
  }
  
  class FooCommand : Command
  {
  }
  
  class ListCommand : Command
  {
  }
  </code></pre>
  
  <p>Now I want to have a struct that stores some data and a Command subclass class ref:</p>
  
  <pre><code>struct CommandVO
  {
      string trigger;
      string category;
      Type commandClass;
  }
  </code></pre>
  
  <p>Somewhere else later on I want to fetch the VO structs from a dictionary and create concrete command objects:</p>
  
  <pre><code>var commandMap = new Dictionary&lt;string, CommandVO?&gt;(100);
  commandMap.Add("foo", new CommandVO
  {
      trigger = "foo", category = "foo commands", commandClass = FooCommand
  });
  commandMap.Add("list", new CommandVO
  {
      trigger = "list", category = "list commands", commandClass = ListCommand
  });
  </code></pre>
  
  <p>...</p>
  
  <pre><code>var commandVO = commandMap["foo"];
  if (commandVO != null)
  {
      var commandClass = commandVO.Value.commandClass;
      // How to instantiate the commandClass to a FooCommand object here?
  }
  </code></pre>
  
  <p>I've checked this <a href="https://riptutorial.com/csharp/example/15938/creating-an-instance-of-a-type" rel="nofollow noreferrer">page</a> for methods on how to instantiate types but since <code>Type</code> doesn't represent any concrete class I wonder how do I get <code>commandClass</code> to instantiate to a proper object of its type? And is it correct in this case to store class declarations as <code>Type</code> in the struct or is there a better approach?</p>