Created
February 27, 2015 01:50
-
-
Save jeffrymorris/a547c942c99293cd4ac7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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