Hi,
I'm trying to create a Fluent Interface to the Winforms Datagrid. This should allow me to use a typed datasource and easy use of properties of properties (Order.Custom.FullName)
I'm adding the columns on initialization and trying to set the property to use there:
dgv.With<Order>().Column("Client Name").On(x => x.Client.FullName);
The original question then poses itself when setting the Datasource:
dgv.SetTypedDatasource<T>(IList<Order> orders)
A big problem here is that Generic Controls are not possible (I guess), so that T cannot be specified for the class, but has to be specified per method...
I want to create a list of anonymous types, based on a given property in a lambda expression:
something like:
ProcessList<Client>(clientList, x => x.FullName);
Is it possible to do something like this:
[Edit] Note that in practice, the expressions will be set earlier, and will be fetched elsewhere...
public void ProcessList<T>(IList<T> sourceList, Expression<Func<T, object>> expression)
{
var list =
(from T x
in sourceList
select new { expression })
.ToList();
// process list .... grid.DataSource = list;
}
So, I would like to create anonymous types based on the given expression. I know I can evaluate that expression to retrieve the correct properties.
I'm kinda stuck, is something like this possible?
Any ideas?