12
禁用序列化我有一個類的對象爲XML序列化對具體物業
[XmlType("PAYMENT")]
public class PaymentXML
{
[XmlElement(ElementName = "REQUEST")]
public RequestXML Request { get; set; }
[XmlElement(ElementName = "META")]
public MetaXML Request { get; set; }
//Property that I dont want to be serialized
public Subscriber Subscriber { get; set; }
}
系列化
var xml = new PaymentXML();
string path = HttpContext.Current.Server.MapPath(@_xmlResponseDir + _responsePath);
using (var sw = new StreamWriter(path))
{
var ns = new XmlSerializerNamespaces();
ns.Add("", "");
var serializer = new XmlSerializer(typeof(PaymentXML), new XmlRootAttribute("XML"));
serializer.Serialize(sw, xml, ns);
}
的問題是,它也序列化Subscriber
財產。我只想將RequestXML
和MetaXML
串行化爲XML。 如何排除序列化過程中的Subscriber
屬性?