I am trying to write a method which uses reflection in order to get the properties and set their values while traversing XElement:Lets say I have a class like this which only provides me XML value to be parsed:\[code\]class XMLController{ public string XML { get{ return @"<FieldGroup name='People' count='20'> <Fields> <Field Name='Jon' LastName='McFly'/> <Field Name='Michael' LastName='Jackson'/> </Fields> </FieldGroup>"; } }}\[/code\]And this is how my Objects look like:\[code\]class FieldGroup{ public string Name {get;set;} public string Count {get;set;} public IEnumerable<Field> Fields {get;set;}}class Field{ public string Name {get;set;} public string LastName {get;set;}}\[/code\]The mapper method traverses \[code\]XElement\[/code\] and since the Node names are matching names with the Objects I am thinking this helps little more but I haven't come up with something really useful. I don't want to pass the type but rather, the method will work with almost every XML passed in with the same format. All it knows the fact that the XML nodes and attributes are matching names.This is what I've done but didn't really worked:\[code\]class XMLObjectMapper{ public T Map<T>(XElement element) where T: class, new() { T entity = (T) Activator.CreateInstance(typeof(T)); if(element.HasAttributes) { MapXMLAttributesToObject<T>(element,entity); } if(element.HasElements) { foreach (var childElement in element.Elements()) { //if the child element has child elements as well, we know this is a collection. if(childElement.HasElements) { var property = GetProperty<T>(childElement.Name.LocalName); property.SetValue(entity,new List<property.PropertyType>()); Map<T>(childElement); } else { var property = GetProperty<T>(childElement.Name.LocalName); var type = Activator.CreateInstance(property.PropertyType); type.Dump(); } } } return entity; } private void MapXMLAttributesToObject<T>(XElement element, T entity) { foreach(XAttribute attribute in element.Attributes()) { var property = GetProperty<T>(attribute.Name.LocalName); property.SetValue(entity,attribute.Value); } } private PropertyInfo GetProperty<T>(string propertyName) { return typeof(T).GetProperty(propertyName,BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance); }}\[/code\]