serialization - include collection property

X

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
 
A

Andrew Faust

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?
 
X

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

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




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 -
 
G

Guest

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/NETSerialization/XMLSerialization.htm

I would recommend a slight restructuring to something like this

class Events
{
public string EventColor;
private List<Event> m_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 said:
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

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




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 -
 
X

xke

beautiful idea / will give it a try tomorrow

thanks,
xke

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/NETSerialization/XMLSerialization.htm

I would recommend a slight restructuring to something like this

class Events
{
public string EventColor;
private List<Event> m_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 said:
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

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

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 -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top