1

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 the Comment 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 ?

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
Claudio Ferraro
  • 4,551
  • 6
  • 43
  • 78
  • Does this answer your question? [Is there a way to make JavaScriptSerializer ignore properties of a certain generic type?](https://stackoverflow.com/questions/6851899/is-there-a-way-to-make-javascriptserializer-ignore-properties-of-a-certain-gener) – Peter Csala Aug 03 '21 at 06:50

0 Answers0