方法接受类型 - 如何让它接受泛型?

Method accepts Type - How to make it accept a generic?

抱歉,如果标题不清楚。我加载了一个库 (RestSharp),我正在尝试围绕 API 调用包装一个函数。它看起来像这样:

RestResponse<object> restResponse = RestClient.Execute<object>(restRequest);

这行得通。我现在正试图将其包含在一个函数中。

static RestResponse<T> ApiCall<T>(object param1, object param2, ...)

RestResponse<T> restResponse = RestClient.Execute<T>(restRequest);

return restResponse;

以上结果"T must be a non abstract type with a public constructor to use it as a parameter of blah blah blah"

这是RestClient.Execute方法的局限性吗?

事实证明这可以通过以下方式完成:

static RestResponse<T> ApiCall<T>(object param1, object param2, ...) where T: new()

RestResponse<T> response = (RestResponse<T>)client.Execute<T>(request);

return restResponse;

我知道这只能在对象具有无参数构造函数的情况下使用。 请随时提供一些更优雅的答案!