title: How to pass the current instance to FieldInfo.GetValue inside the instance?
body: <p>I'm making an abstract class that I need to validate fields in it's descendants. All the validated fields are marked by an attribute and are suppose to be checked for nulls or empty. To do that I get all the fields in the class:</p>
  
  <pre><code>var fields = this.GetType().GetFields().Where(field =&gt; Attribute.IsDefined(field, typeof(MyAttribute))).ToList(); 
  </code></pre>
  
  <p>And then, for every FieldInfo I try to do this:</p>
  
  <pre><code>if (string.IsNullOrEmpty(field.GetValue(this).ToString()))
  {
      // write down the name of the field
  }
  </code></pre>
  
  <p>I get a <strong>System.NullReferenceException: object reference not set to an instance of an object</strong>.</p>
  
  <p>I know <a href="https://stackoverflow.com/questions/7110521/c-using-reflection-to-get-access-to-all-fields-within-a-class-returns-error">I am suppose to pass the instance of a class</a> to the GetValue method. But how can I pass the current instance (the one that's launching the logic)?</p>
  
  <p>Or: Is there an other way of getting the field's value?</p>