title: How do I get the count of attributes that an object has?
body: <p>I've got a class with a number of attributes, and I need to find a way to get a count of the number of attributes it has. I want to do this because the class reads a CSV file, and if the number of attributes (csvcolumns) is less than the number of columns in the file, special things will need to happen. Here is a sample of what my class looks like:</p>
  
  <pre><code>    public class StaffRosterEntry : RosterEntry
      {
          [CsvColumn(FieldIndex = 0, Name = "Role")]
          public string Role { get; set; }
  
          [CsvColumn(FieldIndex = 1, Name = "SchoolID")]
          public string SchoolID { get; set; }
  
          [CsvColumn(FieldIndex = 2, Name = "StaffID")]
          public string StaffID { get; set; }
      }
  </code></pre>
  
  <p>I tried doing this:</p>
  
  <pre><code>var a = Attribute.GetCustomAttributes(typeof(StaffRosterEntry));
  var attributeCount = a.Count();
  </code></pre>
  
  <p>But this failed miserably. Any help you could give (links to some docs, or other answers, or simply suggestions) is greatly appreciated!</p>