Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 1.11 KB

CustomContractResolver.md

File metadata and controls

32 lines (26 loc) · 1.11 KB

Custom IContractResolver

This sample creates a custom Argon.IContractResolver that only serializes a type's properties that begin with a specified character.

var person = new Person
{
    FirstName = "Dennis",
    LastName = "Deepwater-Diver"
};

var startingWithF = JsonConvert.SerializeObject(person, Formatting.Indented,
    new JsonSerializerSettings {ContractResolver = new DynamicContractResolver('F')});

Console.WriteLine(startingWithF);
// {
//   "FirstName": "Dennis",
//   "FullName": "Dennis Deepwater-Diver"
// }

var startingWithL = JsonConvert.SerializeObject(person, Formatting.Indented,
    new JsonSerializerSettings {ContractResolver = new DynamicContractResolver('L')});

Console.WriteLine(startingWithL);
// {
//   "LastName": "Deepwater-Diver"
// }

snippet source | anchor