Geeks With Blogs
Ben Adler's Development Posting solutions as I find them September 2014 Entries
Loop through XML Element and set dynamic properties on object
Here is a handy method that accepts an XElement and an object. It loops through each attribute in the XML element and sets the matching property on the object: public static object SetProperties(object obj, XElement xelement) { foreach (var attribute in xelement.Attributes()) //loop through attributes of element { PropertyInfo propertyInfo = obj.GetType().GetProperty(a... //get property that matches attribute //make sure property exists if (propertyInfo != null) { if (propertyInfo.PropertyType ......

Posted On Tuesday, September 16, 2014 9:39 AM

Copyright © BenAdler | Powered by: GeeksWithBlogs.net