-
-
Notifications
You must be signed in to change notification settings - Fork 109
/
RequestBodySerializer.cs
32 lines (30 loc) · 1.38 KB
/
RequestBodySerializer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Net.Http;
namespace RestEase
{
#pragma warning disable CS0618 // Type or member is obsolete
/// <summary>
/// Helper which knows how to serialize a request body
/// </summary>
public abstract class RequestBodySerializer : IRequestBodySerializer
{
[Obsolete("Override SerializeBody<T>(T body, RequestBodySerializerInfo info) instead", error: true)]
HttpContent IRequestBodySerializer.SerializeBody<T>(T body)
{
// This exists only so that we can assign instances of ResponseDeserializer to the IResponseDeserializer in RestClient
throw new InvalidOperationException("This should never be called");
}
/// <summary>
/// Serialize the given request body
/// </summary>
/// <param name="body">Body to serialize</param>
/// <param name="info">Extra information about the request</param>
/// <typeparam name="T">Type of the body to serialize</typeparam>
/// <returns>HttpContent to assign to the request</returns>
public virtual HttpContent? SerializeBody<T>(T body, RequestBodySerializerInfo info)
{
throw new NotImplementedException($"You must override and implement SerializeBody<T>(T body, RequestBodySerializerInfo info) in {this.GetType().Name}");
}
}
#pragma warning restore CS0618 // Type or member is obsolete
}