I have an EventType and Events classes to serialize/deserialize. In Xml for Events there is a XmlElement named "type".
<?xml version="1.0" encoding="UTF-8"?>
<events type="array">
<event>
<where />
<project-users-can-edit type="boolean">false</project-users-can-edit>
<description />
<attending-user-ids type="integer">164316</attending-user-ids>
<notify-user-names>Levent A.</notify-user-names>
<attending-user-names>Levent A.</attending-user-names>
<status>active</status>
<owner>
<first-name>Levent</first-name>
<id type="integer">164316</id>
<last-name>Arık</last-name>
</owner>
<reminders type="array" />
<notify-user-ids type="integer">164316</notify-user-ids>
<start>2015-06-22T00:00</start>
<repeat />
<all-day type="boolean">true</all-day>
<id type="integer">608945</id>
<end>2015-06-22T23:59</end>
<show-as-busy type="boolean">false</show-as-busy>
<last-changed-on type="date">2015-07-08T09:20:37Z</last-changed-on>
<privacy>
<type>company</type>
</privacy>
<attendees-can-edit type="boolean">false</attendees-can-edit>
*<type>
<name>Yıllık İzin</name>
<id type="integer">104109</id>
<color>C65518</color>
</type>*
<title>Yıllıkİzin</title>
</event>
</events>
But I also have an Xml with the list of EventTypes and with the different xmlelement name "eventtypes".
<?xml version="1.0" encoding="UTF-8"?>
<eventtypes type="array">
<eventtype>
<name>Diğer</name>
<id type="integer">104285</id>
<color>E7C342</color>
</eventtype>
<eventtype>
<name>Hastalık</name>
<id type="integer">104284</id>
<color>399A5A</color>
</eventtype>
<eventtype>
<name>Mazeret İzni</name>
<id type="integer">104110</id>
<color>633C9C</color>
</eventtype>
<eventtype>
<name>ResmiTatil</name>
<id type="integer">104286</id>
<color type="integer">737173</color>
</eventtype>
<eventtype>
<name>Yıllık İzin</name>
<id type="integer">104109</id>
<color>C65518</color>
</eventtype>
</eventtypes>
I am using below class for this. But when I want to deserialize eventtypes Xml I have an exception because of title of XmlRoot attribute.
[Serializable]
[XmlRoot("type")]
public class EventType
{
public EventType()
{
}
[XmlElement("color")]
public string Color { get; set; }
[XmlElement("id")]
public string Id { get; set; }
[XmlElement("name")]
public string Name { get; set; }
}
I know i can write 2 different classes with same properties. But i wonder if there is another way to do it.