Ejemplo n.º 1
0
        /// <summary>
        /// Creates an XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object as a single section to write to a file.
        /// </summary>
        /// <returns>
        /// An XML string containing an unmerged view of the <see cref="T:System.Configuration.ConfigurationSection"/> object.
        /// </returns>
        /// <param name="parentElement">The <see cref="T:System.Configuration.ConfigurationElement"/> instance to use as the parent when performing the un-merge.</param>
        /// <param name="name">The name of the section to create.</param>
        /// <param name="saveMode">The <see cref="T:System.Configuration.ConfigurationSaveMode"/> instance to use when writing to a string.</param>
        protected override string SerializeSection(ConfigurationElement parentElement, string name, ConfigurationSaveMode saveMode)
        {
            ExtensionElementMap.Clear();
            currentSection = this;
            TypeResolver.SetAliases(this);
            this.InitializeSectionExtensions();

            var sb = new StringBuilder();

            using (var writer = MakeXmlWriter(sb))
            {
                writer.WriteStartElement(name, XmlNamespace);
                writer.WriteAttributeString("xmlns", XmlNamespace);
                this.TypeAliases.SerializeElementContents(writer, "alias");
                this.Namespaces.SerializeElementContents(writer, "namespace");
                this.Assemblies.SerializeElementContents(writer, "assembly");
                this.SectionExtensions.SerializeElementContents(writer, "sectionExtension");
                this.Containers.SerializeElementContents(writer, "container");
                writer.WriteEndElement();
            }

            return(sb.ToString());
        }
 /// <summary>
 /// Apply configuration from the default container in the given section.
 /// </summary>
 /// <param name="container">Unity container to configure.</param>
 /// <param name="section">Configuration section.</param>
 /// <returns><paramref name="container"/>.</returns>
 public static IUnityContainer LoadConfiguration(this IUnityContainer container, UnityConfigurationSection section)
 {
     Guard.ArgumentNotNull(container, "container");
     Guard.ArgumentNotNull(section, "section");
     return(container.LoadConfiguration(section, String.Empty));
 }
Ejemplo n.º 3
0
 public ExtensionContext(UnityConfigurationSection section, string prefix, bool saveAliases)
 {
     this.section     = section;
     this.prefix      = prefix;
     this.saveAliases = saveAliases;
 }
Ejemplo n.º 4
0
 public ExtensionContext(UnityConfigurationSection section, string prefix)
     : this(section, prefix, true)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Reads XML from the configuration file.
 /// </summary>
 /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> object, which reads from the configuration file. </param>
 /// <exception cref="T:System.Configuration.ConfigurationErrorsException"><paramref name="reader"/> found no elements in the configuration file.</exception>
 protected override void DeserializeSection(XmlReader reader)
 {
     ExtensionElementMap.Clear();
     currentSection = this;
     base.DeserializeSection(reader);
 }