当前位置: 首页>>代码示例>>C#>>正文


C# IXPathNavigable.ThrowIfNull方法代码示例

本文整理汇总了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;
                });
        }
开发者ID:,项目名称:,代码行数:32,代码来源:

示例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);
                }
            }
        }
开发者ID:,项目名称:,代码行数:54,代码来源:


注:本文中的IXPathNavigable.ThrowIfNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。