I am working on a C# system and a class has one function that returns a System.Threading.Tasks.Task
object and has a property System.Type
ReturnType.
When ReturnType is null i know the method return a Task object. But sadly there is no way to know if the class implementing the interface will return a Task<ReturnType>
or Task<object>
and i need to get the result of this method. I think the easiest way to do it would be to convert the Task<T>
to Task<object>
so i can get the result and handle it using the Type value in ReturnType.
How can i convert a Task<T>
to Task<object>
without knowing the type of T ?
public interface ITaskFactory
{
ReadOnlyCollection<ParameterInfo> ParametersInfo { get; }
Type ReturnType { get; }
Task CreateTask (params object[] args);
}
I need to get the result returned by the Task
that i received by calling CreateTask()