本文整理匯總了C#中System.Xml.XmlWriterSettings.CopyPropertiesFrom方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlWriterSettings.CopyPropertiesFrom方法的具體用法?C# XmlWriterSettings.CopyPropertiesFrom怎麽用?C# XmlWriterSettings.CopyPropertiesFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlWriterSettings
的用法示例。
在下文中一共展示了XmlWriterSettings.CopyPropertiesFrom方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteToString
/// <summary>
/// Returns an XML node as a string with specified formatting
/// </summary>
/// <param name="doc">XmlNode</param>
/// <param name="settingsOverrides">Settings overrides</param>
/// <returns>XML node as a string</returns>
public static string WriteToString(this XDocument doc, object settingsOverrides)
{
var ms = new MemoryStream();
var settings = new XmlWriterSettings {
OmitXmlDeclaration = false,
Indent = true,
Encoding = Encoding.GetEncoding(doc.Declaration.Encoding),
};
if (settingsOverrides != null)
settings.CopyPropertiesFrom(settingsOverrides);
using (var xw = XmlWriter.Create(ms, settings)) {
doc.Save(xw);
xw.Flush();
var sr = new StreamReader(ms);
ms.Seek(0, SeekOrigin.Begin);
return sr.ReadToEnd();
}
}