Conditionally serialize a member

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe

    #1

    Conditionally serialize a member

    I have a member of my class which I only want to serialize in a flag is
    true. So in a way it would be ideal if I could do something like this:

    if (flag == true)
    NonSerializable Attrbiute(mymem ber);

    Is there a simple way to do this?

    Thanks,
    Joe


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Conditionally serialize a member

    Joe,

    No, without custom serialization (implementation of the ISerializable
    interface, as well as the custom serialization constructor), you can't do
    it.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Joe" <jbassking@noem ail.noemailwrot e in message
    news:OOZyDLlGIH A.5276@TK2MSFTN GP04.phx.gbl...
    >I have a member of my class which I only want to serialize in a flag is
    >true. So in a way it would be ideal if I could do something like this:
    >
    if (flag == true)
    NonSerializable Attrbiute(mymem ber);
    >
    Is there a simple way to do this?
    >
    Thanks,
    Joe
    >

    Comment

    • Marc Gravell

      #3
      Re: Conditionally serialize a member

      DataTable has custom serialization, so I don't think this would work.
      You could give it a go (by adding a "bool ShouldSerialize Whatever()")
      but I don't see how it makes sense when serializing a DataTable...
      i.e. missing out one value in (what is essentially) a grid...

      Are you trying to do this for all rows, or just specific rows? If all,
      perhaps consider removing the column (perhaps in a clone of the
      DataSet/DataTable).

      Marc


      Comment

      Working...