i having api xml response, looks like:
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <artists itemsperpage="30"> <artist id="a0d9633b"> <url>http://www.somesite.com/3df8daf.html</url> </artist> </artists>
for deserializing use classes:
[serializableattribute] [xmltypeattribute(typename = "result")] public abstract class result { private int _itemsperpage; [xmlattributeattribute(attributename = "itemsperpage")] public int itemsperpage { { return this._itemsperpage; } set { this._itemsperpage = value; } } } [serializableattribute] [xmltypeattribute(typename = "artists")] [xmlrootattribute(elementname = "artists")] public class artists : result, ienumerable<artist> { private list<artist> _list; [xmlelementattribute(elementname = "artist")] public list<artist> list { { return this._list; } set { this._list = value; } } public artists() { _list = new list<artist>(); } public void add(artist item) { _list.add(item); } ienumerator ienumerable.getenumerator() { return _list.getenumerator(); } public ienumerator<artist> getenumerator() { foreach (artist artist in _list) yield return artist; } } [serializableattribute] [xmltypeattribute(typename = "artist")] [xmlrootattribute(elementname = "artist")] public class artist { private string _mbid; private string _url; [xmlattributeattribute(attributename = "mbid")] public string mbid { { return this._mbid; } set { this._mbid = value; } } [xmlelementattribute(elementname = "url")] public string url { { return this._url; } set { this._url = value; } } public artist() { } }
and how deserialization:
xmlserializer serializer = new xmlserializer(typeof(artists)); artists result = (artists)serializer.deserialize(new streamreader("artists.xml"));
so, the problem is, when deserialization, itemsperpage
doesn't have needed (30) value (it has default 0). however, if remove ienumerable<artist>
interface , deserialize artists, value appear. can remove interface , leaves artists
ienumerator<artist> getenumerator()
method, fine, artists
still can foreach'ed, no longer ienumerable<artist>
. not want. problem not in base class, because can transfer property itemsperpage
artists
class, , deserialization result same.
any ideas how can deserialize itemsperpage value artists
still being ienumerable<artist>
?
Comments
Post a Comment