示例#1
0
 private void SerializeContainerConfiguringElements(XmlWriter writer)
 {
     foreach (var element in this.ConfiguringElements)
     {
         string tag = ExtensionElementMap.GetTagForExtensionElement(element);
         writer.WriteElement(tag, element.SerializeContent);
     }
 }
示例#2
0
        private bool DeserializeContainerConfiguringElement(string elementName, XmlReader reader)
        {
            Type elementType = ExtensionElementMap.GetContainerConfiguringElementType(elementName);

            if (elementType != null)
            {
                this.ReadElementByType(reader, elementType, this.ConfiguringElements);
                return(true);
            }
            return(false);
        }
            /// <summary>
            /// Add a new element to the configuration section schema.
            /// </summary>
            /// <param name="tag">Tag name in the XML.</param>
            /// <param name="elementType">Type the tag maps to.</param>
            public override void AddElement(string tag, Type elementType)
            {
                Unity.Utility.Guard.ArgumentNotNull(elementType, "elementType");

                if (typeof(ContainerConfiguringElement).IsAssignableFrom(elementType))
                {
                    ExtensionElementMap.AddContainerConfiguringElement(this.prefix, tag, elementType);
                }
                else if (typeof(InjectionMemberElement).IsAssignableFrom(elementType))
                {
                    ExtensionElementMap.AddInjectionMemberElement(this.prefix, tag, elementType);
                }
                else if (typeof(ParameterValueElement).IsAssignableFrom(elementType))
                {
                    ExtensionElementMap.AddParameterValueElement(this.prefix, tag, elementType);
                }
                else
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                      Resources.InvalidExtensionElementType,
                                                                      elementType.Name));
                }
            }
        /// <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());
        }
 private static Type GetExtensionElementType(string elementName)
 {
     return(ExtensionElementMap.GetInjectionMemberElementType(elementName));
 }
 /// <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);
 }