Return a type from a string
<p>I'm not really sure where to start with this. I am writing a GUI manager for XNA using my entity component model libraries. I want to be able to dynamically import XML documents to GUI forms. The idea I had was to have an attribute <code>"type"</code> that contains the type of the control. For example <code>type="Image"</code> would tell the parser to make an image. Once it has that it can call it's own XML parsing method to fill in the values. However, I'm stuck at this part. </p>

<p>Consider this document:</p>

<pre><code>&lt;Gui&gt;
  &lt;BGImage type="Image"&gt;
    &lt;Body&gt;
      &lt;Position&gt;
        &lt;X&gt;0&lt;/X&gt;
        &lt;Y&gt;0&lt;/Y&gt;
      &lt;/Position&gt;
    &lt;/Body&gt;
    &lt;ImageRender&gt;
      &lt;Texture&gt;background&lt;/Texture&gt;
      &lt;Color&gt;
        &lt;R&gt;255&lt;/R&gt;
        &lt;G&gt;255&lt;/G&gt;
        &lt;B&gt;255&lt;/B&gt;
        &lt;A&gt;255&lt;/A&gt;
      &lt;/Color&gt;
    &lt;/ImageRender&gt;
  &lt;/BGImage&gt;
  &lt;CheckBox type="Checkbox"&gt;
    &lt;Body&gt;
      &lt;Position&gt;
        &lt;X&gt;20&lt;/X&gt;
        &lt;Y&gt;20&lt;/Y&gt;
      &lt;/Position&gt;
    &lt;/Body&gt;
    &lt;TileRender&gt;
      &lt;Index&gt;0&lt;/Index&gt;
      &lt;Texture&gt;checkbox&lt;/Texture&gt;
      &lt;Color&gt;
        &lt;R&gt;255&lt;/R&gt;
        &lt;G&gt;255&lt;/G&gt;
        &lt;B&gt;255&lt;/B&gt;
        &lt;A&gt;255&lt;/A&gt;
      &lt;/Color&gt;
    &lt;/TileRender&gt;
    &lt;TextRender&gt;
      &lt;Text&gt;Checkbox&lt;/Text&gt;
      &lt;Font&gt;spritefont&lt;/Font&gt;
    &lt;/TextRender&gt;
  &lt;/CheckBox&gt;
&lt;/Gui&gt;
</code></pre>

<p>What I am looking to do is have a class parse this XML document and do the following.
Any tags with a type attribute are added to the form as the type they represent. For example, I have an Image class which represents an image, BGImage in the example should make an Image and be added to the form. What I need is a way to relate the type="Image" to the class Image.</p>

<p>I already have a method I use to add entities to the game, my problem lies with a way to make a string a type and instantiate a new entity from that.</p>

<p>What I am looking to do is return a type from a string, and I'm not really sure that is possible. Is there any way to do this in C#, or am I attacking this from the wrong angle?</p>
