且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何编写好的离线在线调度程序

更新时间:2023-10-03 08:27:58

You can add the new() constraint:

public class DispatcherProxy<TOnline, TOffline, TContract>
    where TOnline : class, new()
    where TOffline : class, new()
    where TContract : class //isn't TContract an interface?
{
    public TContract Instance { get; set; }

    public bool IsConnected { get; set; }

    public DispatcherProxy()
    {
        // Asume that I check if it's connected or not
        if (this.IsConnected)
            this.Instance = new TOnline() as TContract;
        else
            this.Instance = new TOffline() as TContract;
    }
}