Cannot convert type 'Task' to 'Task'

后端 未结 3 1372
忘掉有多难
忘掉有多难 2020-12-03 10:49

I have the following function with a delegate parameter that accepts a type of one interface and returns a task of another.

public void Bar(Func

        
3条回答
  •  一向
    一向 (楼主)
    2020-12-03 11:38

    I am using another version of GeneralizeTask, which is stated by @Recursive, on Asp Net Core Framework. Here it is:

    public static Task GeneralizeTask(this Task task, CancellationToken cancellationToken = default) 
     where TBase : class 
     where TDerived : TBase
    {
        var result = task.ContinueWith(t => (TBase)t.Result, cancellationToken);
        return result;
    }
    

提交回复
热议问题