title: Type equality check in C#
body: <p>With</p>
  
  <pre><code>public abstract class CompositionPlugin { ... }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class MyCompositionPlugin : CompositionPlugin { ... }
  </code></pre>
  
  <p>I want to check if an object's type is equal to a given type:</p>
  
  <pre><code>public class Framework {
  
      public IList&lt;CompositionPlugin&gt; CompositionPlugins = new List&lt;CompositionPlugin&gt;();
  
      public CompositionPlugin GetCompositionPlugin(Type ofType)
      {
          foreach (CompositionPlugin plugin in CompositionPlugins)
          {
              if (plugin.GetType().Equals(ofType))
                  return plugin;
          }
  
          throw new ArgumentException("A composition plugin of type " + ofType.FullName + " could not be found");
      }
  }
  </code></pre>
  
  <p>Where the method is called like this:</p>
  
  <pre><code>Framework framework = new Framework();
  // Adding the plugin to the framework is done by loading an assembly and
  // checking if it contains plugin-compatible classes (i.e. subclasses
  // of &lt;CompositionPlugin&gt;)
  framework.RegisterAssembly("E:\\Projects\\Framework\\MyPlugin\\bin\\Debug\\MyPlugin.dll");
  CompositionPlugin plugin = framework.GetCompositionPlugin(typeof(MyCompositionPlugin));
  </code></pre>
  
  <p>Yet, when testing, this check always fails, even though I most definitely have that type of object in the list that I request.</p>
  
  <p>In my understanding, it should return the first instance of <code>MyCompositionPlugin</code> that is found inside the <code>CompositionPlugins</code>-List.</p>
  
  <p>Is my type check wrong? Why? How is it done correctly?</p>