Skip to content

Instantly share code, notes, and snippets.

@jeffrymorris
Created February 27, 2015 01:50
Show Gist options
  • Save jeffrymorris/a547c942c99293cd4ac7 to your computer and use it in GitHub Desktop.
Save jeffrymorris/a547c942c99293cd4ac7 to your computer and use it in GitHub Desktop.
public class IgnoreFieldContractResolver : DefaultContractResolver
{
public IgnoreFieldContractResolver() { }
public IgnoreFieldContractResolver(string fieldToIgnore)
{
FieldToIgnore = fieldToIgnore;
}
public string FieldToIgnore { get; set; }
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
{
if (string.IsNullOrWhiteSpace(FieldToIgnore))
{
throw new InvalidOperationException("FieldToIgnore must be non-null and not-empty.");
}
return (from x in base.CreateProperties(type, memberSerialization)
where x.PropertyName != FieldToIgnore
select x).ToList();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment