Get the Field Name from a Class Data

How to Get the list of fields from a class, let say "ProposalData".
ProposalData contains public property Id, Title, and SubmissionDate. We will get those three property using System.Reflection member class called "PropertyInfo". See the example below:

public List<string> GetFieldProposalDataData()
{
List<string>listField = new List<string>();
PropertyInfo[] propertyInfos;
propertyInfos = typeof(ProposalData).GetProperties();
foreach (PropertyInfo propertyInfo in propertyInfos)
{
listField.Add(propertyInfo.Name);
}
return listField;
}

Okay, may it helps

No comments:

Post a Comment