我有一个通用类,想要创建一个该类的列表。然后在运行时获取该项的类型。
类
public class Job<T>
{
public int ID { get; set; }
public Task<T> Task { get; set; }
public TimeSpan Interval { get; set; }
public bool Repeat { get; set; }
public DateTimeOffset NextExecutionTime { get; set; }
public Job<T> RunOnceAt(DateTimeOffset executionTime)
{
NextExecutionTime = executionTime;
Repeat = false;
return this;
}
}
我想要实现的目标
List<Job<T>> x = new List<Job<T>>();
public void Example()
{
//Adding a job
x.Add(new Job<string>());
//The i want to retreive a job from the list and get it's type at run time
}
Job
和Job<string>
中需要什么,但是根据您的代码,似乎您可以在非泛型Job
类中拥有除了Task
和RunAtOnce
之外的所有内容。 - p.s.w.g((Job<string>)job).Task
。 - p.s.w.g