By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,712 Members | 1,369 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,712 IT Pros & Developers. It's quick & easy.

serialization - include collection property

P: n/a
xke
Why the collection property is not included in the ouput
serialization ?

I have a custom generic collection (implements icollection): Events of
objects: Event.

Event is a simple class exposing, let's say, one property: name

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class
Events Implements ICollection
Public EventColor as string
........

Everything works except when I save the xml file I'm expecting to get
smth like:

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>

EVENTCOLOR attribute is not in the xml, any idea ?

Thanks,
xke

Oct 22 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.com
http://www.andrewfaust.com
"xke" <xk****@gmail.comwrote in message
news:11**********************@e34g2000pro.googlegr oups.com...
Why the collection property is not included in the ouput
serialization ?

I have a custom generic collection (implements icollection): Events of
objects: Event.

Event is a simple class exposing, let's say, one property: name

Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class
Events Implements ICollection
Public EventColor as string
........

Everything works except when I save the xml file I'm expecting to get
smth like:

<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>

EVENTCOLOR attribute is not in the xml, any idea ?

Thanks,
xke
Oct 23 '07 #2

P: n/a
xke
Hi Andrew,

Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.

It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.

Thanks,
xke

On Oct 22, 10:06 pm, "Andrew Faust" <and...@andrewfaust.comwrote:
In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com

"xke" <xke...@gmail.comwrote in message

news:11**********************@e34g2000pro.googlegr oups.com...
Why the collection property is not included in the ouput
serialization ?
I have a custom generic collection (implements icollection): Events of
objects: Event.
Event is a simple class exposing, let's say, one property: name
Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class
Events Implements ICollection
Public EventColor as string
........
Everything works except when I save the xml file I'm expecting to get
smth like:
<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>
EVENTCOLOR attribute is not in the xml, any idea ?
Thanks,
xke- Hide quoted text -

- Show quoted text -

Oct 23 '07 #3

P: n/a
Sorry. Misread your original post.

According to this article the Serializer only supports writing out the
actual objects contained in an ICollection and not the actual properties of
the collection itself.

http://www.diranieh.com/NETSerializa...ialization.htm

I would recommend a slight restructuring to something like this

class Events
{
public string EventColor;
private List<Eventm_Events;
public Event[] UpcomingEvents
{
get { return m_Events.ToArray(); }
set {
m_Events = new List<Event>();
m_Events.AddRange(value);
}
}
}

Then serialize the Events class.

"xke" wrote:
Hi Andrew,

Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.

It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.

Thanks,
xke

On Oct 22, 10:06 pm, "Andrew Faust" <and...@andrewfaust.comwrote:
In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?

--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com

"xke" <xke...@gmail.comwrote in message

news:11**********************@e34g2000pro.googlegr oups.com...
Why the collection property is not included in the ouput
serialization ?
I have a custom generic collection (implements icollection): Events of
objects: Event.
Event is a simple class exposing, let's say, one property: name
Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class
Events Implements ICollection
Public EventColor as string
........
Everything works except when I save the xml file I'm expecting to get
smth like:
<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>
EVENTCOLOR attribute is not in the xml, any idea ?
Thanks,
xke- Hide quoted text -
- Show quoted text -


Oct 23 '07 #4

P: n/a
xke
beautiful idea / will give it a try tomorrow

thanks,
xke

On Oct 23, 1:28 pm, Andrew Faust <afa...@nospam.nospamwrote:
Sorry. Misread your original post.

According to this article the Serializer only supports writing out the
actual objects contained in an ICollection and not the actual properties of
the collection itself.

http://www.diranieh.com/NETSerializa...ialization.htm

I would recommend a slight restructuring to something like this

class Events
{
public string EventColor;
private List<Eventm_Events;
public Event[] UpcomingEvents
{
get { return m_Events.ToArray(); }
set {
m_Events = new List<Event>();
m_Events.AddRange(value);
}
}

}

Then serialize the Events class.

"xke" wrote:
Hi Andrew,
Yes, EventName gets serialized as member of Event class. Question
would be: why the parent collection class properties don't get
serialized ?
Problem I have is not with the Event class but with Events class (the
collection). I thought Events class members will be also serialized.
It's quite basic what I am trying to do, it should work. If you have
any ideas pls help.
Thanks,
xke
On Oct 22, 10:06 pm, "Andrew Faust" <and...@andrewfaust.comwrote:
In your example EventColor isn't a part of the class Event, and thus
wouldn't get serialized along with it. The only member Event has is
EventName. Is EventName getting serialized? What output are you getting?
--
Andrew Faust
andrew[at]andrewfaust.comhttp://www.andrewfaust.com
"xke" <xke...@gmail.comwrote in message
>news:11**********************@e34g2000pro.googleg roups.com...
Why the collection property is not included in the ouput
serialization ?
I have a custom generic collection (implements icollection): Events of
objects: Event.
Event is a simple class exposing, let's say, one property: name
Public Class Event
<XmlAttribute("name")_
Public EventName As string
end class
Events Implements ICollection
Public EventColor as string
........
Everything works except when I save the xml file I'm expecting to get
smth like:
<?xml version="1.0" encoding="utf-8"?>
<events xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" EVENTCOLOR="some color">
<event eventname="some name" />
</events>
EVENTCOLOR attribute is not in the xml, any idea ?
Thanks,
xke- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -

Oct 23 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.