How can I access dynamically properties from a generated LINQ class ?
Cause I would like to be able to customize the displayed table columns where Partner is the LINQ Class generated from a SQL Server Database Table.
<table class='grid'> <thead> <tr> <% foreach (Column c in (IEnumerable)ViewData['columns']) { %> <th><%= c.Title %></th> <% } %> </tr> </thead> <tbody> <% foreach (Partner p in (IEnumerable)ViewData.Model) { %> <tr> <% foreach (Column c in (IEnumerable)ViewData['columns']) { %> ????? <th> <%= p.GetProperty(c.Name) %> </th> ????? <% } %> </tr> <% } %> </tbody> </table>
Any idea how the code of the p.GetProperty(c.Name) method could look like ?
Forgive me if the Question is very simple but as I’m new to C# and LINQ I really couldn’t figure it out.
Reflection is a pretty good fit here, but really – everything is known at compile time. So it’s possible to specify everything at design time.