I have a class with a number of attributes, and I need to find a way to count the number of its attributes. I want to do this because the class reads the CSV file, and if the number of attributes (csvcolumns) is less than the number of columns in the file, special things must happen. Here is an example of what my class looks like:
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; }
}
I tried to do this:
var a = Attribute.GetCustomAttributes(typeof(StaffRosterEntry));
var attributeCount = a.Count();
But it failed. Any help you could give (links to some documents or other answers or just suggestions) is greatly appreciated!
source
share