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


C# XmlTextReader.?.Close方法代码示例

本文整理汇总了C#中System.Xml.XmlTextReader.?.Close方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.?.Close方法的具体用法?C# XmlTextReader.?.Close怎么用?C# XmlTextReader.?.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlTextReader的用法示例。


在下文中一共展示了XmlTextReader.?.Close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Load

 /// <summary>
 /// Read the .config from a file.
 /// </summary>
 /// <param name="appConfigFile"></param>
 internal void Load(string appConfigFile)
 {
     XmlTextReader reader = null;
     try
     {
         reader = new XmlTextReader(appConfigFile);
         reader.DtdProcessing = DtdProcessing.Ignore;
         Read(reader);
     }
     catch (XmlException e)
     {
         throw new AppConfigException(e.Message, appConfigFile, (reader != null ? reader.LineNumber : 0), (reader != null ? reader.LinePosition : 0), e);
     }
     catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
     {
         throw new AppConfigException(e.Message, appConfigFile, (reader != null ? reader.LineNumber : 0), (reader != null ? reader.LinePosition : 0), e);
     }
     finally
     {
         reader?.Close();
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:26,代码来源:AppConfig.cs

示例2: ValidateSectionXml

        // Verify that the string is valid xml, begins with the expected section name,
        // and contains no more or less than a single element.
        //
        // Throws a ConfigurationErrorsException if there is an error.
        private void ValidateSectionXml(string xmlElement, string configKey)
        {
            if (string.IsNullOrEmpty(xmlElement))
                return;

            XmlTextReader reader = null;
            try
            {
                XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.Default, Encoding.Unicode);
                reader = new XmlTextReader(xmlElement, XmlNodeType.Element, context);

                // Verify that the it is an element
                reader.Read();
                if (reader.NodeType != XmlNodeType.Element)
                    throw new ConfigurationErrorsException(string.Format(SR.Config_unexpected_node_type, reader.NodeType));

                // Verify the name of the element is a section
                string group, name;
                SplitConfigKey(configKey, out group, out name);
                if (reader.Name != name)
                    throw new ConfigurationErrorsException(string.Format(SR.Config_unexpected_element_name, reader.Name));

                for (;;)
                {
                    if (!reader.Read())
                    {
                        // ensure there is a matching end element
                        if (reader.Depth != 0)
                        {
                            throw new ConfigurationErrorsException(string.Format(SR.Config_unexpected_element_end),
                                reader);
                        }

                        break;
                    }

                    switch (reader.NodeType)
                    {
                        // disallowed node types within a section
                        case XmlNodeType.XmlDeclaration:
                        case XmlNodeType.DocumentType:
                            throw new ConfigurationErrorsException(SR.Config_invalid_node_type, reader);
                    }


                    // don't allow XML after the end element
                    if ((reader.Depth <= 0) && (reader.NodeType != XmlNodeType.EndElement))
                        throw new ConfigurationErrorsException(SR.Config_more_data_than_expected, reader);
                }
            }
            finally
            {
                reader?.Close();
            }
        }
开发者ID:chcosta,项目名称:corefx,代码行数:59,代码来源:MgmtConfigurationRecord.cs


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