从通用基类获取实现的类型

Ale*_*lex 2 c# generics inheritance base-class

我可能措辞完全错了,但基本上,我有以下基类:

public class ScheduleableService<T> : ServiceBase
        where T : IJob
{
        var x = typeof(T);
}
Run Code Online (Sandbox Code Playgroud)

这个的实现是这样的:

public class MyScheduledService: ScheduleableService<MyScheduledJob>
{
    //MyScheduledJob implements IJob
}
Run Code Online (Sandbox Code Playgroud)

基本上,我需要的是,在我的基类ScheduleableService中,能够获取MyScheduledService类型 - 有没有办法我可以做到这一点而不传递它.

以下作品,但是很难......

public class ScheduleableService<T, S> : ServiceBase
    where T : IJob
    where S : ServiceBase
{

    var x = typeof(T);
    var y = typeof(S);
}
Run Code Online (Sandbox Code Playgroud)

执行:

public class MyScheduledService: ScheduleableService<MyScheduledJob,
                                                     MyScheduledService>
{
    //MyScheduledJob implements IJob
}
Run Code Online (Sandbox Code Playgroud)

Ant*_*lev 11

this.GetType() 或者我错过了什么?