I have a list of objects of some class defined as
public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } var personList = new List<Person>(); personList.Add(new Person { FirstName = "Alex", LastName = "Friedman", Age = 27 });
and display this list as a table with the property name as the column header ( full source code )
var propertyArray = typeof(T).GetProperties(); foreach (var prop in propertyArray) result.AppendFormat("<th>{0}</th>", prop.Name);
and get
FirstName | LastName | Age ---------------------------------- Alex Friedman 27
I want to have some custom names like
First Name | Last Name | Age
Question: How to define column headers for each property of the Person class? Should I use custom attributes for properties or is there a better way?
source share