I am having a class named link
public class Link
{
public string rel { get; set; }
public string href { get; set; }
public string name { get; set; }
}
Using this class i have to create an json file ("JsonConvert.SerializeObject(Link)") but for some cases i dont want to hide name property and show only rel and href properties and other case i want show all of the 3 properties..
can you please suggest me what to do for this..

Pradeep ShetRank #595 · 4K reputationPosted Jan 21, 2015, 8:57 PM EST
I way i knew is, set property NullValueHandling saying ignore the null values, and purposely set ti to null, incase you dont want that property to be emitted.
JsonSerializer _jsonWriter = new JsonSerializer
{
NullValueHandling = NullValueHandling.Ignore
};
Hope this answers your query.
Bhushan GawaleRank #299 · 8.4K reputationPosted Jan 21, 2015, 10:18 PM EST
[JsonIgnore]