public void SectionHandlerTest()
        {
            XmlSerializerTransformerData settings = transformer.Deserialize(GetSection(xmlString)) as XmlSerializerTransformerData;

            Assert.IsNotNull(settings);
            Assert.AreEqual(transformerName, settings.Name);
            Assert.AreEqual(typeof(XmlSerializerTransformer).AssemblyQualifiedName, settings.TypeName);
            Assert.AreEqual(includeType, settings.XmlIncludeTypes[includeName].TypeName);
        }
Exemplo n.º 2
0
        /// <summary>
        /// <para>
        /// Reads configuration settings for a user-defined configuration section.
        /// </para>
        /// </summary>
        /// <param name="sectionName">
        /// <para>The configuration section to read.</para>
        /// </param>
        /// <returns>
        /// <para>The configuration settings for <paramref name="sectionName"/>.</para>
        /// </returns>
        /// <exception cref="ArgumentException">
        /// <para><paramref name="sectionName"/>can not be <see langword="null"/> (Nothing in Visual Basic).</para>
        /// </exception>
        /// <exception cref="ConfigurationException">
        /// <para><paramref name="sectionName"/> is not valid for this configuration.</para>
        /// </exception>
        public object ReadConfiguration(string sectionName)
        {
            ValidateSection(sectionName);

            object configurationSection = sections.GetSection(sectionName);

            if (IsConfigurationSectionCached(configurationSection))
            {
                return(configurationSection);
            }

            IStorageProviderReader storageProviderReader = CreateStorageProvider(sectionName);

            object configurationSettings = storageProviderReader.Read();

            if (configurationSettings == null)
            {
                return(null);
            }

            ITransformer transformer = CreateTransformer(sectionName);

            if (transformer != null)
            {
                configurationSection = transformer.Deserialize(configurationSettings);
            }
            else
            {
                configurationSection = configurationSettings;
            }

            ConfigurationChangedEventHandler changed = new ConfigurationChangedEventHandler(OnExternalConfigurationChanged);

            sections.AddSection(sectionName, configurationSection, changed, storageProviderReader);

            return(configurationSection);
        }