I have the following static field in my class
private static Func<IDataReader, Project> Make = reader =>
new Project
{
Name = reader["ProjectName"].AsId(),
StartDate = reader["StartDate"].AsDateTime(),
EndDate = reader["EndDate"].AsDateTime()
};
I’m trying to do the same using a generic interface, but can’t work out how to define the generic type. It would be something along the lines of this.
private static Func<IDataReader, IDefinition<T>> Make<T> = reader =>
new Definition<T>
{
Name = reader["DefinitionName"].AsId()
};
This obviousily doesn’t work, but does anyone know how I could achieve this?
You can’t have a generic field; you can, however, push this into a generic static type:
and use
You might want to tidy that up, though (the internal field, etc)