[XmlIgnore]
public DateTime ApplicationDatetime { get; set; }
[XmlElement("ApplicationDatetime")]
public string ApplicationDatetimeString
{
get { return ApplicationDatetime.ToString("yyyy-MM-dd HH:mm:ss"); }
set { ApplicationDatetime = DateTime.Parse(value); }
}
static public string SerializeToXml<T>(T obj)
{
string xmlString = string.Empty;
//XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
//using (MemoryStream ms = new MemoryStream())
//{
// xmlSerializer.Serialize(ms, obj);
// xmlString = Encoding.UTF8.GetString(ms.ToArray());
//}
Encoding encoding = Encoding.UTF8;
using (MemoryStream memoryStream = new MemoryStream())
{
XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("", "");
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, encoding);
xmlTextWriter.Formatting = Formatting.None;
xmlSerializer.Serialize(xmlTextWriter, obj, namespaces);
xmlTextWriter.Flush();
xmlTextWriter.Close();
xmlString = encoding.GetString(memoryStream.ToArray());
}
return xmlString;
}
string queryParameters = WebUtils.SerializeToXml(posQueryParameters);
<Entity><EntityName>我和coffee</EntityName><PId>110101198505012511</PId><LoanId>c70215bbc6dd4722b51d2bb93c1a81bd</LoanId><BankCardNo /><MobilePhone /><CheckEmployee>dkx4003</CheckEmployee><ApplicationDatetime>2019-11-07 15:01:52</ApplicationDatetime><Role>PR</Role></Entity>