I think I understand. You are saying that you don't need the filter, you already have done that; you're wanting to get the mapped column name. First see this answer.
That said, based on @John Arlen's answer:
foreach (var prop in data[0].GetType().GetProperties())
{
Console.WriteLine("{0}, Type {1}", prop.Name, prop.PropertyType);
}
The problem here is that this should normally give you:
prop1, *some type*
prop2, *some type*
prop3, *some type*
The confusion is that you are somehow specifying columns before you know the names, and yet in your code example you are using the column names. The columns that you specify should match the column names; prop1
in your code should correspond to the column prop1
in the data source. You were implying that you wanted to filter which columns to get (and which columns to not get) based on the column names.
So this is assuming that you already know beforehand which columns you want, based on some other (unspecified) criteria; that is, if you know that you are getting prop1
, prop2
, and prop3
but not propX
or propY
. Obviously you can't get the column/property names before you filter columns/properties if you don't know the names.
Edit
It occurs to me that you may be wanting to determine which fields are getting filled, and which are not. This might work if you know that none of the fields are null:
foreach (var prop in data[0].GetType().GetProperties())
{
if (prop.GetValue(data[0], null) != null)
Console.WriteLine("{0}, Type {1}", prop.Name, prop.PropertyType);
}
Edit 2
Also see this SO question.