Using reflection I have a tool that gets class properties:
foreach (MemberInfo member in typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public))
{
WriteValue(streamWriter, member.Name);
}
Is there a way to query "GetProperties" to return MemberInfo in the order in which they are defined in the class. I seriously doubt it, but thought I'd ask.
class Person
{
public int Id { get; set; }
public int Age { get; set; }
}
I would like to get MemberInfo in this order: Id, Age
source
share