title: Getting all fields - including inherited ones - with a custom attribute
body: <p>I've got a custom attribute <code>BacksCache</code> that I'm using to mark fields in a class that need to be "defaulted" when certain conditions are met.</p>
  
  <p>I'm using the following code:</p>
  
  <pre><code>Type type = obj.GetType();
  FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy);
  
  foreach (FieldInfo field in fields)
  {
    foreach (Attribute at in field.GetCustomAttributes(true))
    if (at is BacksCache)
    {
      field.SetValue(obj, Utils.DefaultValue(field.FieldType));
    }
  }
  </code></pre>
  
  <p>This code works fine, provided that the class inheritance hierarchy is flat.  That is to say, if <code>type</code> is the Type that declares all the attributed fields, everything's great.  As soon as I have a class <code>A</code> from which descends class <code>B</code> (<code>B : A</code>) and <code>B</code> has some attributed fields things fall apart: only the fields declared by <code>A</code> are detected and "defaulted".</p>
  
  <p>The fields in question are <code>private</code> or <code>private volatile</code>, if that makes any difference.</p>
  
  <p>Any ideas on how to fix this?</p>