XmlDeserializer to handle inline lists
Posted
by d1k_is
on Stack Overflow
See other posts from Stack Overflow
or by d1k_is
Published on 2010-04-07T05:51:39Z
Indexed on
2010/04/07
5:53 UTC
Read the original article
Hit count: 289
Im looking at implementing a fix in an XmlDeserializer to allow for element lists without a specific containing element.
The XmlDeserializer im basing off checks for a list object type but then it gets the container element im trying to figure out how to get around this and make it work both ways.
enter code here var t = type.GetGenericArguments()[0];
var list = (IList)Activator.CreateInstance(type);
var container = GetElementByName(root, prop.Name.AsNamespaced(Namespace));
var first = container.Elements().FirstOrDefault();
var elements = container.Elements().Where(d => d.Name == first.Name);
PopulateListFromElements(t, elements, list);
prop.SetValue(x, list, null);
The XML im working with is from the google weather API (forecast_conditions elements)
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
<forecast_information>...</forecast_information>
<current_conditions>...</current_conditions>
<forecast_conditions>...</forecast_conditions>
<forecast_conditions>...</forecast_conditions>
<forecast_conditions>...</forecast_conditions>
</weather>
EDIT: Im looking at this as an update to the RESTsharp open source .net library
© Stack Overflow or respective owner