XMLWriter和XMLDictionaryWriter有什么区别?在哪种情况下,每种情况通常使用?
XmlWriter是一个抽象类,其中XmlDictionaryWriter是继承自己的类之一,它本身就是一个抽象类.
原文链接:https://www.f2er.com/xml/292906.html我正在黑暗中采取一种刺激,您希望使用DataContractSerializer或通常使用de / serialization. XmlDictionaryWriter是WCF使用它进行de / serialization的基类.
从那里我将推断,在XmlDictionaryWriter中必须有一些性能调优,以使其在WCF de / serialization任务中更具性能.事实上,如果你调用WriteObject(Stream,object)而不是WriteObject(XmlWriter,object)或WriteObject(XmlDictionaryWriter,object)方法,它将为你创建一个XmlDictionaryWriter
public virtual void WriteObject(Stream stream,object graph) { CheckNull(stream,"stream"); XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream,Encoding.UTF8,false); this.WriteObject(writer,graph); writer.Flush(); }