﻿// Decompiled with JetBrains decompiler
// Type: System.Configuration.NameValueFileSectionHandler
// Assembly: System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// MVID: 5ABD58FD-DF31-44FD-A492-63F2B47CC9AF
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.dll

using System;
using System.Configuration.Internal;
using System.IO;
using System.Runtime;
using System.Xml;

namespace System.Configuration
{
  /// <summary>
  /// Provides access to a configuration file. This type supports the .NET Framework configuration infrastructure and is not intended to be used directly from your code.
  /// </summary>
  /// <filterpriority>2</filterpriority>
  public class NameValueFileSectionHandler : IConfigurationSectionHandler
  {
    /// <summary>
    /// Initializes a new instance of the <see cref="T:System.Configuration.NameValueFileSectionHandler"/> class.
    /// </summary>
    [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
    public NameValueFileSectionHandler()
    {
    }

    /// <summary>
    /// Creates a new configuration handler and adds it to the section-handler collection based on the specified parameters.
    /// </summary>
    /// 
    /// <returns>
    /// A configuration object.
    /// </returns>
    /// <param name="parent">The parent object.</param><param name="configContext">The configuration context object.</param><param name="section">The section XML node.</param><exception cref="T:System.Configuration.ConfigurationErrorsException">The file specified in the file attribute of <paramref name="section"/> exists but cannot be loaded.- or -The name attribute of <paramref name="section"/> does not match the root element of the file specified in the file attribute.</exception><filterpriority>2</filterpriority><PermissionSet><IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true"/></PermissionSet>
    public object Create(object parent, object configContext, XmlNode section)
    {
      object parent1 = parent;
      XmlNode xmlNode = section.Attributes.RemoveNamedItem("file");
      object @static = NameValueSectionHandler.CreateStatic(parent1, section);
      if (xmlNode != null && xmlNode.Value.Length != 0)
      {
        string path2 = xmlNode.Value;
        IConfigErrorInfo configErrorInfo = xmlNode as IConfigErrorInfo;
        if (configErrorInfo == null)
          return (object) null;
        string str = Path.Combine(Path.GetDirectoryName(configErrorInfo.Filename), path2);
        if (File.Exists(str))
        {
          ConfigXmlDocument configXmlDocument = new ConfigXmlDocument();
          try
          {
            configXmlDocument.Load(str);
          }
          catch (XmlException ex)
          {
            throw new ConfigurationErrorsException(ex.Message, (Exception) ex, str, ex.LineNumber);
          }
          if (section.Name != configXmlDocument.DocumentElement.Name)
            throw new ConfigurationErrorsException(System.SR.GetString("Config_name_value_file_section_file_invalid_root", new object[1]
            {
              (object) section.Name
            }), (XmlNode) configXmlDocument.DocumentElement);
          @static = NameValueSectionHandler.CreateStatic(@static, (XmlNode) configXmlDocument.DocumentElement);
        }
      }
      return @static;
    }
  }
}
