You're probably looking for a generic function -- this allows your function to specify a type parameter:
public void DoWork<TClass>(int time)
where TClass : quartz.ijob
{
IJobDetail job = JobBuilder.Create<TClass>()
.WithIdentity("job1", "group1")
.Build();
}
Edit
You can also place a restriction on the type parameter, which seems to be what is required here. Use the syntax where TClass : quartz.ijob
.
Edit #2
Note that callers of a generic method must specify the type parameter. So, you'd have to call:
DoWork<SomeClassType>(123);
However, if the signature of the method includes a parameter of the generic type, then the compiler can use that to infer the type. So, if the signature is:
public void DoWork<TClass>(int time, TClass instance)
where TClass : quartz.ijob
Then a caller could invoke it like this:
var myInstance = new SomeClassType(); // SomeClassType must inherit quartz.ijob
DoWork(123, myInstance);
Above, the type of myInstance
is known at compile time, so the compiler can infer the generic type. However, if your type instance is boxed, then the type isn't known until runtime, and the compiler can't help you:
function SomethingOrOther(object instance)
{
DoWork(123, instance); // will not compile, as the compiler doesn't know the type of "instance"
}
In this scenario, it is possible to call DoWork
anyway, by using reflection (see MakeGenericMethod
). However, this approach of using reflection on generics gets complicated, fast. It also defeats the purpose of generics (ie, compile-time safety), and usually indicates a design flaw.