Accessing Object properties in Linq to XML



I am attempting to build an XML string using Linq to XML. a is an IList<Object>, making x an Object. Each object is comprised of two properties, DisplayName and ID. I'm not sure how to reference those specific properties.


The below code runs but an exception is thrown "unable to cast object of type 'system.object[]' to type 'system.collections.arraylist'."


How do I access the properties of x?



XDocument InstancePickerUserResponse =
new XDocument(
new XElement("Values",
new XAttribute("Count", a.Count),
a.Select(x =>
new XElement("Value",
new XAttribute("DisplayName", ((ArrayList)x)[1]),
new XAttribute("Id", ((ArrayList)x)[0])
)
)
)
);

No comments:

Post a Comment