Skip to content

Instantly share code, notes, and snippets.

@luisgoncalves
luisgoncalves / SubTypesConverter.cs
Created October 3, 2018 22:27
A Json.NET converter that handles an hierarchy of types based on a custom discriminator property
class SubTypesConverter<T> : JsonConverter<T> where T: new()
{
[ThreadStatic]
private static bool isWriting;
private readonly string discriminatorName;
private readonly Dictionary<string, Func<T>> factories;
private readonly Dictionary<Type, string> discriminators;
@luisgoncalves
luisgoncalves / DumpToConsoleDelegatingHandler.cs
Created September 5, 2018 16:28
DumpToConsoleDelegatingHandler
class DumpToConsoleDelegatingHandler : DelegatingHandler
{
public DumpToConsoleDelegatingHandler()
{
InnerHandler = new HttpClientHandler();
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Console.WriteLine("");