title: Making custom JsonConverter respect ItemTypeNameHandling when serializing with JSON.NET
body: <p>I have an object with a list of base class sub-objects. Sub-objects need a custom converter. I can't make my custom converter respect <code>ItemTypeNameHandling</code> option.</p>
  
  <p>Sample code (create a new C# Console project, add JSON.NET NuGet package):</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using Newtonsoft.Json;
  
  namespace My {
      class Program {
          private static void Main () {
              Console.WriteLine(JsonConvert.SerializeObject(
                  new Box { toys = { new Spintop(), new Ball() } },
                  Formatting.Indented));
              Console.ReadKey();
          }
      }
  
      [JsonObject] class Box
      {
          [JsonProperty (
              ItemConverterType = typeof(ToyConverter),
              ItemTypeNameHandling = TypeNameHandling.Auto)]
          public List&lt;Toy&gt; toys = new List&lt;Toy&gt;();
      }
      [JsonObject] class Toy {}
      [JsonObject] class Spintop : Toy {}
      [JsonObject] class Ball : Toy {}
  
      class ToyConverter : JsonConverter {
          public override void WriteJson (JsonWriter writer, object value, JsonSerializer serializer) {
              serializer.Serialize(writer, value);
          }
          public override object ReadJson (JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
              return serializer.Deserialize(reader, objectType);
          }
          public override bool CanConvert (Type objectType) {
              return typeof(Toy).IsAssignableFrom(objectType);
          }
      }
  }
  </code></pre>
  
  <p>Produced output:</p>
  
  <pre><code>{
    "toys": [
      {},
      {}
    ]
  }
  </code></pre>
  
  <p>Necessary output (this is what happens if I comment <code>ItemConverterType = typeof(ToyConverter),</code> line):</p>
  
  <pre><code>{
    "toys": [
      {
        "$type": "My.Spintop, Serialization"
      },
      {
        "$type": "My.Ball, Serialization"
      }
    ]
  }
  </code></pre>
  
  <p>I've tried temporarily changing value of <code>serializer.TypeNameHandling</code> in <code>ToyConverter.WriteJson</code> method, but it affects unrelated properties. (Of course, my real converter is more complex than that. It's just an example with base functionality.)</p>
  
  <p><strong>Question:</strong> How to make my custom <code>JsonConverter</code> respect <code>ItemTypeNameHandling</code> property of <code>JsonProperty</code> attribute?</p>