Reading XML structure using dynamic features



Consider I have an XML file which is loaded into an XElement or something like it. One way of reaching the tag values is to use Element() method.


Is there any way to facilitate this using dynamic objects. For example I want to replace



var val = xelement.Element("Name").Value


with



var dyn = (dynamic)xelement;
var val = dyn.Name;


It's a good idea to have nested properties too. For example:



var val = dyn.Person.Name;

No comments:

Post a Comment