I have a generic class and I want to create a list of it. and then at run time I get the type of the item
public class Job
{
pub
If all of your jobs are of same type (e.g. Job) you can simply create a list of that type:
List> x = new List>();
x.Add(new Job());
However, if you want to mix jobs of different types (e.g. Job and Job) in the same list, you'll have to create a non-generic base class or interface:
public abstract class Job
{
// add whatever common, non-generic members you need here
}
public class Job : Job
{
// add generic members here
}
And then you can do:
List x = new List();
x.Add(new Job());
If you wanted to get the type of a Job at run-time you can do this:
Type jobType = x[0].GetType(); // Job
Type paramType = jobType .GetGenericArguments()[0]; // string