我有一堂课:
[DataContract]
public class Result
{
[DataMember] public String Log {get; set;}
[DataMember] public String Data {get; set;}
}
我通过 WCF 发送这个类,它工作正常。但是我想在接收后将这个类保存到一个xml文件中。我试着写:
var serializer = new DataContractSerializer(typeof (T),null,int.MaxValue,
false,true,null,new SharedTypeXmlResolver());
var settings = new XmlWriterSettings { Indent = true };
using (var backing = new StringWriter(CultureInfo.InvariantCulture))
{
using (var writer = XmlWriter.Create(backing, settings))
{
serializer.WriteObject(writer, result);
}
return backing.ToString();
}
但我想将“日志”属性保存到 XML 文件中,并且不想保存“数据”属性。我该怎么做?