Is it possible to instantiate a template class at runtime for example:
Type type = Type.GetType("iTry.Workflow.Person");
WorkflowPropertyViewModel<type> propViewModel = new WorkflowPropertyViewModel<type>();
This obviously does not work. Is there some other way to do it?
The Generic class looks like the following:
public class WorkflowPropertyViewModel<T> : IProperty<T>
{
public Task<T> ValueAsync
{
get;
set;
}
public T Value
{
get;
set;
}
public IQueryable<T> PossibleItems
{
get;
set;
}
}
Yes, you can instantiate a generic class with a type known only at runtime, e.g.:
However, this snippet uses reflection and dynamic typing, both of which may cause a lot of maintenance problems, so you would be better off using them very carefully or finding a simpler solution.