I know about ScriptIgnoreAttribute
.
But what if I want to ignore a property based on criteria. For example how to ignore a nullable property on serialization only if it's null and doesn't contain any value?
https://docs.microsoft.com/dotnet/api/system.web.script.serialization.scriptignoreattribute
Use [ScriptIgnore]
using System;
using System.Web.Script.Serialization;
public class Group
{
// The JavaScriptSerializer ignores this field.
[ScriptIgnore]
public string Comment;
// The JavaScriptSerializer serializes this field.
public string GroupName;
}