internal static bool DecodeXmlTextReaderValue(object instance, PropertyInfo propertyInfo, XmlReader xmlTextReader)
{
try
{
// find related property by name if not provided as parameter
if (propertyInfo == null)
propertyInfo = instance.GetType().GetProperty(xmlTextReader.Name, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
if (propertyInfo == null)
return false;
// unescaped characters <>&
if (propertyInfo.PropertyType.Equals(typeof(string)))
propertyInfo.SetValue(instance, Decode(xmlTextReader.ReadInnerXml().Trim()), null);
else if (propertyInfo.PropertyType.Equals(typeof(DateTime)))
propertyInfo.SetValue(instance, ParseRfc822DateTime(xmlTextReader.ReadInnerXml().Trim()), null);
else
propertyInfo.SetValue(instance, TypeDescriptor.GetConverter(propertyInfo.PropertyType).ConvertFromString(xmlTextReader.ReadInnerXml().Trim()), null);
}
catch (Exception e)
{
Debug.WriteLine(propertyInfo.Name + ", " + propertyInfo.PropertyType.Name + " / " + instance.ToString() + " " + e.Message);
return false;
}
return true;
}