public void DeserializeNode(XmlNode node, object Instance, bool ThrowOnError = false) { mapXPathNodeToObject[Utility.GetXPath(node)] = Instance; foreach (XmlNode propertyNode in node.SelectNodes("Property")) { try { MemberInfox propertyInfo = GetPropertyInfo(propertyNode, Instance); object PropertyValue = propertyInfo.GetValue(); var childs = GetChild(propertyNode); object refObj = CheckIfReferenceNode(propertyNode); if (refObj != null) { propertyInfo.SetValue(refObj); } else if (Utility.IsSimpleType(propertyInfo.ValueType))//Simple property { SetPropertyValue(Instance, propertyNode); } else if (childs.Count > 0 && childs[0].Name == "Array")//Array found { propertyInfo.SetValue(DeserializeIEnumerable(childs[0], propertyInfo.ValueType, null, ThrowOnError)); } else//Complex types { if (PropertyValue == null) { if (!Utility.TryCreateInstance(propertyInfo.ValueType, out PropertyValue)) { continue; } propertyInfo.SetValue(PropertyValue); } DeserializeNode(propertyNode, PropertyValue, ThrowOnError); } } catch { if (ThrowOnError) { throw; } } } }
private void SetPropertyValue(object obj, XmlNode propertyNode) { MemberInfox property = GetPropertyInfo(propertyNode, obj); if (property == null) { return; } property.SetValue(propertyNode.InnerText.Trim().ConvertTo(property.ValueType)); }