Reputation: 1
I am trying to understand a complex (for me) method.
Here is the signature for the method:
public static List<T> GetAll<R, T>(RestClient client, RestRequest request) where R : new()
Now from this I understand that it will return a generic type and that it requires a RestClient and RestRequest object as parameters.
But I dont understand what the:
<R, T>
and
where R : new()
bits actually means?
Can someone elaborate please?
Upvotes: 0
Views: 64
Reputation: 9519
These are Generic type constraints
Essentially, this signature says:
public static List<T> GetAll<R, T>(RestClient client, RestRequest request) where R : new()
public
- accessible outside of this Assembly
static
- non-instance, static (aka class) method
List<T>
- returns a System.Collections.Generic.List<T>
- an array-like collection where items inside it have type T
GetAll<R, T>
- GetAll
is the method name; R,T
-> i imagine, RequestType
and T
where t is ResponseType
.
(RestClient client, RestRequest request)
are just arguments to the method
where R : new()
- the method is only valid for types R
where R
has a public parameterless constructor (e.g. you can type somewhere new R()
)
Usages could be:
List<string> GetAll<object, string>(RestClient client, RestRequest request);
It is not a really good signature because it is not clear why the author needs R
.
Upvotes: 7