I am trying to create a generic method for my search, but I don't know how to return list of fields from my class.
Let's say I've got a class:
public class Table
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
}
And now I want to return a list that would look like this:
"ID"
"Name"
"Address"
How do I do that?
tried something like this:
FieldInfo[] fields = typeof(T).GetFields(
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
string[] names = Array.ConvertAll<FieldInfo, string>(fields,
delegate(FieldInfo field) { return field.Name; });
But it has some unnecessary text after field names
EDIT
It's not duplicate because in my situation GetProperties().Select(f => f.Name) made a difference