public string Customer { get { if (((IEnumerable<XElement>)content.Descendants("Customer")).Count<XElement>() == 0) return ""; else return content.Descendants("Customer").Single().Value; } set { content.Descendants("Customer").Single().Value = value; } }~~Bonnie
> public class Order > { > private XElement content = new XElement("Order", > new XElement("ID"), > new XElement("Customer") > ); > > public XElement XMLContent > { > get { return content; } > set { content = XMLContent; } > } > > public string ID > { > get { return content.Descendants("ID").Single().Value; } > set { content.Descendants("ID").Single().Value = value; } > } > > public string Customer > { > get { return content.Descendants("Customer").Single().Value; } > set { content.Descendants("Customer").Single().Value = value; } > } > }>This works fine until I set the XMLContent to (again a fictitious example - but assume that it is a valid thing to do) an XElement that does not contain a 'Customer' element. In this situation I'd like the Customer property to return an empty string. If I inspect the Customer property in the debugger it shows an exception - but I can't seem to trap for this situation anywhere (I was thinking I could do this in the Customer accessor....)