Last active
April 4, 2019 15:01
-
-
Save hesenger/88e4b4f10b3cabf15147b379c8f193b2 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 OnlyRootContractResolver : CamelCasePropertyNamesContractResolver | |
{ | |
protected Type _root; | |
protected List<string> _included; | |
public OnlyRootContractResolver(Type root, IEnumerable<string> included) | |
{ | |
_root = root; | |
_included = new List<string>(included ?? new string[0]); | |
} | |
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization) | |
{ | |
var res = base.CreateProperties(type, memberSerialization); | |
if (type == _root) | |
return res; | |
var qry = from t in res | |
where _included.Contains(t.PropertyName) || Type.GetTypeCode(t.PropertyType) != TypeCode.Object | |
select t; | |
return qry.ToList(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment