I am trying to determine what to use ...
I have a requirement to pass an IEnumerable<TSource> to a function that writes the entity members' values to file. Here is what the IEnumerable looks like:
var persons = new[] {
new Person {
RecordID = 0,
PersonFName = "Joe",
PersonMName = "",
PersonLName = "Smith",
PersonZip="75227"
},
new Person {
RecordID = 1,
PersonFName = "Mary",
PersonMName = "Hada",
PersonLName = "Lamb",
PersonZip="75217"
}};
What is the best way to pass the IEnumerable to a function that reads each entity so I can read each field value?
I was thinking that I would use something like:
void WriteData<TSource>(Expression<IEnumerable<Person>> expression)
{
// do stuff
}
I'm having trouble finding resources that explain how to determine when you should use an Expression versus just passing IEnumerable. And then, how do I create the Expression that reflects persons ?
Ideally, it seems like I would call WriteData like so:
WriteData(persons);
Am I even headed in the right direction?
IQueryableinterface, I highly recommend reading Matt Warren's LINQ: Building an IQueryable provider series. Warning: Metaprogramming can be complex and requires time and patience