本文整理汇总了C#中IXPathNavigable.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# IXPathNavigable.ThrowIfNull方法的具体用法?C# IXPathNavigable.ThrowIfNull怎么用?C# IXPathNavigable.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IXPathNavigable
的用法示例。
在下文中一共展示了IXPathNavigable.ThrowIfNull方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveAsync
/// <summary>
/// The preferred way to save - this should be a <see cref="System.Xml.XmlDocument" /> straight from CCP.
/// </summary>
/// <param name="filename">The filename.</param>
/// <param name="xdoc">The xml to save.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException"></exception>
public static async Task SaveAsync(string filename, IXPathNavigable xdoc)
{
xdoc.ThrowIfNull(nameof(xdoc));
EveMonClient.EnsureCacheDirInit();
XmlDocument xmlDoc = (XmlDocument)xdoc;
XmlNode characterNode = xmlDoc.SelectSingleNode("//name");
filename = characterNode?.InnerText ?? filename;
// Writes in the target file
string fileName = Path.Combine(EveMonClient.EVEMonXmlCacheDir, $"{filename}.xml");
string content = Util.GetXmlStringRepresentation(xdoc);
await FileHelper.OverwriteOrWarnTheUserAsync(fileName,
async fs =>
{
using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8))
{
await writer.WriteAsync(content);
await writer.FlushAsync();
await fs.FlushAsync();
}
return true;
});
}
示例2: SaveDocumentAsync
/// <summary>
/// Saves the document to the disk.
/// </summary>
/// <param name="filename">The filename.</param>
/// <param name="xmlDocument">The XML document.</param>
/// <returns></returns>
/// <exception cref="System.ArgumentNullException">filename or xmlDocument</exception>
public static async Task SaveDocumentAsync(string filename, IXPathNavigable xmlDocument)
{
filename.ThrowIfNull(nameof(filename));
xmlDocument.ThrowIfNull(nameof(xmlDocument));
using (SaveFileDialog sfd = new SaveFileDialog())
{
sfd.DefaultExt = "xml";
sfd.Filter = @"XML (*.xml)|*.xml";
sfd.FileName = filename;
if (sfd.ShowDialog() != DialogResult.OK)
return;
try
{
string content = Util.GetXmlStringRepresentation(xmlDocument);
// Moves to the final file
await FileHelper.OverwriteOrWarnTheUserAsync(
sfd.FileName,
async fs =>
{
using (StreamWriter writer = new StreamWriter(fs, Encoding.UTF8))
{
await writer.WriteAsync(content);
await writer.FlushAsync();
await fs.FlushAsync();
}
return true;
});
}
catch (IOException err)
{
ExceptionHandler.LogException(err, true);
MessageBox.Show($"There was an error writing out the file:\n\n{err.Message}",
@"Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (XmlException err)
{
ExceptionHandler.LogException(err, true);
MessageBox.Show($"There was an error while converting to XML format.\r\nThe message was:\r\n{err.Message}",
@"Save Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}