title: Ignore [JsonIgnore] Attribute on Serialization / Deserialization
body: <p>Is there a way I can ignore Json.NET's <code>[JsonIgnore]</code> attribute on a class that I don't have permission to modify/extend?</p>
  
  <pre><code>public sealed class CannotModify
  {
      public int Keep { get; set; }
  
      // I want to ignore this attribute (and acknowledge the property)
      [JsonIgnore]
      public int Ignore { get; set; }
  }
  </code></pre>
  
  <p>I need all properties in this class to be serialized/deserialized. I've tried subclassing Json.NET's <code>DefaultContractResolver</code> class and overriding what looks to be the relevant method:</p>
  
  <pre><code>public class JsonIgnoreAttributeIgnorerContractResolver : DefaultContractResolver
  {
      protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
      {
          JsonProperty property = base.CreateProperty(member, memberSerialization);
  
          // Serialize all the properties
          property.ShouldSerialize = _ =&gt; true;
  
          return property;
      }
  }
  </code></pre>
  
  <p>but the attribute on the original class seems to always win:</p>
  
  <pre><code>public static void Serialize()
  {
      string serialized = JsonConvert.SerializeObject(
          new CannotModify { Keep = 1, Ignore = 2 },
          new JsonSerializerSettings { ContractResolver = new JsonIgnoreAttributeIgnorerContractResolver() });
  
      // Actual:  {"Keep":1}
      // Desired: {"Keep":1,"Ignore":2}
  }
  </code></pre>
  
  <p>I dug deeper, and found an interface called <code>IAttributeProvider</code> that can be set (it had a value of "Ignore" for the <code>Ignore</code> property, so that was a clue this might be something that needs changing):</p>
  
  <pre><code>...
  property.ShouldSerialize = _ =&gt; true;
  property.AttributeProvider = new IgnoreAllAttributesProvider();
  ...
  
  public class IgnoreAllAttributesProvider : IAttributeProvider
  {
      public IList&lt;Attribute&gt; GetAttributes(bool inherit)
      {
          throw new NotImplementedException();
      }
  
      public IList&lt;Attribute&gt; GetAttributes(Type attributeType, bool inherit)
      {
          throw new NotImplementedException();
      }
  }
  </code></pre>
  
  <p>But the code isn't ever hit.</p>