title: Get all base property declarations within a class hierarchy
body: <p>Consider this interesting set of types:</p>
  
  <pre><code>class A     { public virtual     int MyProperty { get; set; } }
  class B : A { public override    int MyProperty { get; set; } }
  class C : B { public new virtual int MyProperty { get; set; } }
  class D : C { public override    int MyProperty { get; set; } }
  class E : D { public new         int MyProperty { get; set; } }
  </code></pre>
  
  <p>I see three different properties here, with five implementations hiding or overriding each other.</p>
  
  <p>I'm trying to get the set of property <strong>declarations</strong> for type <code>E</code>:</p>
  
  <pre><code>A.MyProperty
  C.MyProperty
  E.MyProperty
  </code></pre>
  
  <p>But my code below gives me the set of property <strong>implementations</strong>:</p>
  
  <pre><code>A.MyProperty
  B.MyProperty
  C.MyProperty
  D.MyProperty
  E.MyProperty
  </code></pre>
  
  <p>What do I need to do to get the property declarations?</p>
  
  <p>Or is there any chance that <code>B.MyProperty</code> will ever return a value other than <code>A.MyProperty</code> for any instance of <code>E</code>?</p>
  
  <p>If my approach is heading in the wrong direction: How do I get all property members of a type including any hidden ones, but not including those that will never have different values?</p>
  
  <hr>
  
  <pre><code>void GetProperties(Type type)
  {
      if (type.BaseType != null)
      {
          GetProperties(type.BaseType);
      }
  
      foreach (var item in type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public))
      {
          Console.WriteLine("{0}.{1}", type.Name, item.Name);
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Desired outputs:</p>
  
  <pre>
  typeof(A)       typeof(B)       typeof(C)       typeof(D)       typeof(E)
  ------------    ------------    ------------    ------------    ------------
  A.MyProperty    A.MyProperty    A.MyProperty    A.MyProperty    A.MyProperty
                                  C.MyProperty    C.MyProperty    C.MyProperty
                                                                  E.MyProperty
  </pre>