PC Review


Reply
Thread Tools Rate Thread

collectionbase derived class and XmlAttribute

 
 
Dirk Reske
Guest
Posts: n/a
 
      21st Sep 2005
Hello,

I've created a collection.

public class MyCollection:CollectionBase
{
public int Version;

[...]
}

I want to serialize it...and it works!
but what do I have to do, that the XmlSerializer serializes the Version
property also?

thx

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Tim Haughton
Guest
Posts: n/a
 
      21st Sep 2005
"Dirk Reske" <_(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> public class MyCollection:CollectionBase
> {
> public int Version;
>
> [...]
> }
>
> I want to serialize it...and it works!
> but what do I have to do, that the XmlSerializer serializes the Version
> property also?


IIRC the XmlSerializer doesn't serialize fields, just public properties.
Wrap it.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton


 
Reply With Quote
 
Dirk Reske
Guest
Posts: n/a
 
      21st Sep 2005
public class MyCollection:CollectionBase
{
private int version;
public int Version
{
get { return this.version; }
set { this.version = value; }
}

[...]
}

doesn't work to...

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Tim Haughton
Guest
Posts: n/a
 
      21st Sep 2005
Are you marking your class as serializable? Your extension won't inherit the
attribute.

--
Regards,

Tim Haughton

Agitek
http://agitek.co.uk
http://blogitek.com/timhaughton

"Dirk Reske" <_(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> public class MyCollection:CollectionBase
> {
> private int version;
> public int Version
> {
> get { return this.version; }
> set { this.version = value; }
> }
>
> [...]
> }
>
> doesn't work to...
>
> *** Sent via Developersdex http://www.developersdex.com ***



 
Reply With Quote
 
Dirk Reske
Guest
Posts: n/a
 
      21st Sep 2005
yes,

here the top of my class:
[Serializable]
public class Contacts:System.Collections.CollectionBase
{
private int version = 0;

[XmlAttribute("Version")]
public int Version
{
get { return this.version; }
set { this.version = value; }
}

[...]
}

but the XmlSerializer doesn't serialize the Version Property

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Mark Rockmann
Guest
Posts: n/a
 
      23rd Sep 2005
> public class MyCollection:CollectionBase
> {
> public int Version;
>
> [...]
> }
>
> I want to serialize it...and it works!
> but what do I have to do, that the XmlSerializer serializes the Version
> property also?


The XmlSerializer does *never* serialize properties of collection classes,
just the content is serialized. You have to move the Version propery to
another class, probably the class containing the collection property.

Example (shown as Xml):
<parent>
<items>
<item />
<item />
<item />
</items>
<version>1.0.0.0</version>
</parent>

Mark


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Serialization of the class derived from CollectionBase Just D. Microsoft C# .NET 2 28th Jan 2005 02:20 PM
Clearing CollectionBase derived list Colin Basterfield Microsoft C# .NET 2 2nd Jul 2004 05:38 AM
CollectionBase derived class not saving design time items niyad Microsoft Dot NET Framework Forms 4 18th Feb 2004 10:16 AM
CollectionBase derived class not saving design time items niyad Microsoft C# .NET 3 18th Feb 2004 10:16 AM
CollectionBase derived class not saving design time items niyad Microsoft VC .NET 3 18th Feb 2004 10:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:51 PM.