In C# I have the following object:
public class Item
{ }
public class Task<T>
{ }
public class TaskA<T> : Task<T>
{ }
public class TaskB<T> : Task<T>
{ }
I want to dynamically create TaskA or TaskB using C# reflection (Activator.CreateInstance). However I wouldn’t know the type before hand, so I need to dynamically create TaskA based on string like “namespace.TaskA” or “namespace.TaskAB”.
Check out this article and this simple example. Quick translation of same to your classes …
Per your edit: For that case, you can do this …
To see where I came up with backtick1 for the name of the generic class, see this article.
Note: if your generic class accepts multiple types, you must include the commas when you omit the type names, for example: