title: Given a C# Type, Get its Base Classes and Implemented Interfaces
body: <p>I'm working on a game engine in C#. The class I'm working on is called <code>CEntityRegistry</code>, and its job is to keep track of the many instances of <code>CEntity</code> in the game. My goal is to be able to query the <code>CEntityRegistry</code> with a given type, and get a list of each <code>CEntity</code> of that type. </p>
  
  <p>What I'd like to do, therefore, is maintain a map:</p>
  
  <pre><code>private IDictionary&lt;Type, HashSet&lt;CEntity&gt;&gt; m_TypeToEntitySet;
  </code></pre>
  
  <p>And update the registry thusly:</p>
  
  <pre><code>private void m_UpdateEntityList()
          {
              foreach (CEntity theEntity in m_EntitiesToRemove.dequeueAll())
              {
                  foreach (HashSet&lt;CEntity&gt; set in m_TypeToEntitySet.Values)
                  {
                      if (set.Contains(theEntity))
                          set.Remove(theEntity);
                  }
              }
              foreach (CEntity theEntity in m_EntitiesToAdd.dequeueAll())
              {
                  Type entityType = theEntity.GetType();
                  foreach (Type baseClass in entityType.GetAllBaseClassesAndInterfaces())
                    m_TypeToEntitySet[baseClass].Add(theEntity);
  
              }
          }
  </code></pre>
  
  <p>The problem I have is that there is no function <code>Type.GetAllBaseClassesAndInterfaces</code>- How would I go about writing it?</p>