Reputation: 10156
I want to create a serializable C#
class for the XML
below.
<xml>
<versions>
<org.geotools.util.Version>
<version>1.0.0</version>
</org.geotools.util.Version>
<org.geotools.util.Version>
<version>1.1.0</version>
</org.geotools.util.Version>
<org.geotools.util.Version>
<version>2.0.0</version>
</org.geotools.util.Version>
</versions>
<gml>
<entry>
<version>V_20</version>
<gml>
<srsNameStyle>URN2</srsNameStyle>
<overrideGMLAttributes>false</overrideGMLAttributes>
</gml>
</entry>
<entry>
<version>V_10</version>
<gml>
<srsNameStyle>XML</srsNameStyle>
<overrideGMLAttributes>true</overrideGMLAttributes>
</gml>
</entry>
<entry>
<version>V_11</version>
<gml>
<srsNameStyle>URN</srsNameStyle>
<overrideGMLAttributes>false</overrideGMLAttributes>
</gml>
</entry>
</gml>
</xml>
I know I could do something like this:
[XmlRoot(ElementName = "xml")]
interface IServiceSettings : IXmlSerializable
{
[XmlArray(ElementName = "versions")]
[XmlArrayItem(ElementName = "org.geotools.util.Version")]
IList<string> Versions { get; set; }
}
But it is working only for <org.geotools.util.Version>
elements that would contain strings only. How to expand this code over my case?
Upvotes: 0
Views: 70
Reputation: 13495
What about this:
[XmlRoot(ElementName = "xml")]
interface IServiceSettings<T> : IXmlSerializable
{
[XmlArray(ElementName = "versions")]
[XmlArrayItem(ElementName = "org.geotools.util.Version")]
IList<T> Versions { get; set; }
}
Then the implementation of the interface will be generic as well
public class ServiceSettings<T> : IServiceSettings<T>
Upvotes: 2