I use the JavascriptSerializer
to serialize an object like this:
using System;
using System.Web.Script.Serialization;
public class Group
{
[ScriptIgnore]
public string Comment;
public string GroupName;
}
Now I would like to reuse the same object with the same Comment
property for a different serialization problem.
- In the first case I would like to
ScriptIgnore
theComment
field - In the second case I would like to not ignore that field.
Is there a programmatic way to choose whether to ignore or not the Comment
field just before serializing the object using an external condition, or I'm forced to create a second object with only one field of difference ?