public object Xml2Obj(string xml, Type type) { if (xml == null) { return(null); } if (type.IsSubclassOf(typeof(IXmlConverter))) { IXmlConverter converter = GetDefaultValue(type) as IXmlConverter; converter.Xml2Object(xml); return(converter); } if (IsPrimitiveXmlType(type) && !IsXmlString(xml)) { if (type == typeof(string)) { return(xml); } if (string.IsNullOrEmpty(xml)) { return(GetDefaultValue(type)); } if (type == typeof(int)) { return(Convert.ToInt32(xml, CultureInfo.InvariantCulture)); } if (type == typeof(double)) { return(Convert.ToDouble(xml, CultureInfo.InvariantCulture)); } ; if (type == typeof(bool)) { return(Convert.ToBoolean(xml, CultureInfo.InvariantCulture)); } if (type == typeof(DateTime)) { xml = string.Format(CultureInfo.InvariantCulture, "<{0}>{1}</{0}>", "dateTime", xml); return(MsgTransfer.Xml2Object(xml, type, true)); } } else { if (string.IsNullOrEmpty(xml)) { return(GetDefaultValue(type)); } return(MsgTransfer.Xml2Object(xml, type, true)); } Exception <TypeConvertExceptionMessage> exception = new Exception <TypeConvertExceptionMessage>(); exception.Reference = xml; exception.ErrorInfo.TargetTypeName = type.FullName; throw exception; }