RestSharp updating use of AddHandler mathod to use factory delegate

According to the source code at https://github.com/restsharp/RestSharp/blob/dev/src/RestSharp/RestClient.cs:

 [Obsolete("Use the overload that accepts a factory delegate")]
 public void AddHandler(string contentType, IDeserializer deserializer) =>
    AddHandler(contentType, () => deserializer);

The obsolete overload just calls the AddHandler(string contentType, Func<IDeserializer> deserializerFactory) overload.

So you can replace your code to add your custom handler as follows:

RestClient.AddHandler("application/json", () => { return CustomJsonSerializer.Instance; });

Tags:

C#

Restsharp