HighTechTalks DotNet Forums  

Conditionally render during serialization

Dotnet XML microsoft.public.dotnet.xml


Discuss Conditionally render during serialization in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Noah Subrin
 
Posts: n/a

Default Conditionally render during serialization - 04-07-2004 , 04:25 PM






Hello,

I have a class like the following

public class person
public FirstName as string
public LastName as string

end class


I am serializing the class. I want to conditionally not render a property if
it is blank. For example if LastName = "", I don't want to display it.

I am serializing it using the following:



Dim p as person = new Person

p.FirstName = "John"



Dim sw As StringWriter = New StringWriter

Dim ser As XmlSerializer = New XmlSerializer(GetType(Person))

ser.Serialize(sw,p)

Any ideas?



Thanks in advance.







Reply With Quote
  #2  
Old   
Alex Shirshov
 
Posts: n/a

Default Re: Conditionally render during serialization - 04-09-2004 , 03:28 AM






Hello, Noah!
You wrote on Wed, 7 Apr 2004 15:25:16 -0500:

NS> I have a class like the following

NS> public class person
NS> public FirstName as string
NS> public LastName as string

NS> end class

NS> I am serializing the class. I want to conditionally not render a
NS> property if it is blank. For example if LastName = "", I don't want to
NS> display it.

It may be done by implementing IXmlSerializable interface.

[Sorry, skipped]


With best regards, Alex Shirshov.



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.