title: C# Switch For Types Of A Class
body: <p>I have the following method which takes a type of class as a parameter:</p>
  
  <pre><code>public void test(Type proType){
  
  }
  </code></pre>
  
  <p>I currently have a large <code>if else</code> which looks like:</p>
  
  <pre><code>if(proType == typeof(Class)){}
  </code></pre>
  
  <p>As there is about ten this looks untidy.</p>
  
  <p>I tried turning this in to a switch but couldn't get it to work.</p>
  
  <p>Is there any better practice to this or away to get a switch statement to work?</p>
  
  <pre><code>           switch (proType)
              {
                  case typeof(ClassName):
                      break;
              }
  </code></pre>
  
  <p>"A constant value required"</p>
  
  <p>The function is been called like <code>test(typeof(class))</code></p>
  
  <p>So the aim is i have a Big object which contains many small classes.</p>
  
  <p>The typeof(class) switch/if statement allows me to decide what container to go in to get the objects out.</p>