473,473 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditionally serialize a member

Joe
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)
NonSerializableAttrbiute(mymember);

Is there a simple way to do this?

Thanks,
Joe
Oct 29 '07 #1
2 1357
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]
- mv*@spam.guard.caspershouse.com

"Joe" <jb*******@noemail.noemailwrote in message
news:OO**************@TK2MSFTNGP04.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)
NonSerializableAttrbiute(mymember);

Is there a simple way to do this?

Thanks,
Joe

Oct 29 '07 #2
DataTable has custom serialization, so I don't think this would work.
You could give it a go (by adding a "bool ShouldSerializeWhatever()")
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
Oct 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ian Tompsett | last post by:
H I was wondering if it possible for an object to serialize/deserialize itself from XML. I'd be guessing that it would need to use the XmlSerializer class, but that seems to want to create a...
2
by: Brad | last post by:
I have tried both the binary and the XML serialization; both give the same results. I have an object with a MemoryStream member. When I serialize and deserialize the object, the MemoryStream...
1
by: Noah Subrin | last post by:
Hello, I have a class like the following public class person public FirstName as string public LastName as string end class
0
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
1
by: Mike Pollett | last post by:
Hi, I have used the ISerializable interface before and the code below worked fine. Until I derived it from CollectionBase. The code will still serialize and deserialize the properties in this class...
5
by: Andrew Alford | last post by:
I have a class that I created that requires me to serialize it for specific reasons. I have an SqlConnection that is a private member of the class, and therfore the serialization fails. The...
1
by: js | last post by:
Does anybody knows how to solve the problem? I added attribute to the following classes in Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get the error. Thanks. ...
10
by: JurgenvonOerthel | last post by:
Consider the classes Base, Derived1 and Derived2. Both Derived1 and Derived2 derive publicly from Base. Given a 'const Base &input' I want to initialize a 'const Derived1 &output'. If the...
4
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.