title: How to check if object is of any of given types in C#
body: <p>I am working with Unity Engine where there is a base class <code>Component</code> and multiple classes deriving from it, including <code>Transform</code>, <code>MeshRenderer</code> and many classes created by me.</p>
  
  <p>I want to execute an action (in this case <code>Destroy</code> all the components that aren't of types: <code>Transform</code>, <code>MeshRenderer</code>, <code>MeshFilter</code>, <code>Collider</code> and <code>BuildMenuItem</code>). My basic approach looks like this:</p>
  
  <pre><code>Component[] components = obj.GetComponents&lt;Component&gt;();
  foreach (var component in components) {
      if (component is MeshFilter)
          continue;
      if (component is MeshRenderer)
          continue;
      if (component is Transform)
          continue;
      if (component is Collider)
          continue;
      if (component is BuildMenuItem)
          continue;
  
      Destroy(component);
  }
  </code></pre>
  
  <p>In my opinion it looks ugly and the only way to shorten it I found is to use <code>||</code> operator, but it doesn't fix a lot and IMO looks even worse. Is there a cleaner way of implementing that?</p>