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


C# ConfigurationBuilder.ReadConfiguration方法代码示例

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


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

示例1: ReadWriteWebConfigTest

 public void ReadWriteWebConfigTest()
 {
     string configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, webConfigFile);
     using (ConfigurationBuilder builder = new ConfigurationBuilder(configFile))
     {
         ConfigurationSettings configData = new ConfigurationSettings(mockConfigSection);
         configData.ConfigurationSections.Add(GetConfigurationSection());
         builder.WriteMetaConfiguration(configData);
         builder.WriteConfiguration(mockConfigSection, data);
         MockConfigurationData readData = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
         Assert.IsNotNull(readData);
         Assert.AreEqual(data.ToString(), readData.ToString());
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:14,代码来源:ConfigurationBuilderFixture.cs

示例2: ReadAndWriteToEncryptedConfiguration

        public void ReadAndWriteToEncryptedConfiguration()
        {
            const string sectionName = "MyEncryptedConfig";

            KeyAlgorithmPair keyAlgorithmPair = new KeyAlgorithmPair();
            keyAlgorithmPair.Key = new SymmetricAlgorithmKeyCreator(typeof(RijndaelManaged).AssemblyQualifiedName).GenerateKey();
            keyAlgorithmPair.AlgorithmTypeName = typeof(RijndaelManaged).AssemblyQualifiedName;

            FileKeyAlgorithmPairStorageProvider provider = new FileKeyAlgorithmPairStorageProvider();
            provider.ConfigurationName = "FileKeyAlgorithmPairStorageProviderData";

            using (ConfigurationBuilder builder = new ConfigurationBuilder())
            {
                // change wher the file is
                RuntimeConfigurationView view = new RuntimeConfigurationView(new ConfigurationContext(new NonDisposingWrapper(builder)));

                FileKeyAlgorithmPairStorageProviderData fileData = (FileKeyAlgorithmPairStorageProviderData)view.GetKeyAlgorithmPairStorageProviderData();
                fileData.Path = Path.GetTempFileName();
                provider.Initialize(view);
                provider.Save(keyAlgorithmPair);
                builder.WriteConfiguration(sectionName, data);
                MockConfigurationData myData = (MockConfigurationData)builder.ReadConfiguration(sectionName);
                Assert.AreEqual(myData.ToString(), data.ToString());
                builder.ClearSectionCache();
                myData = (MockConfigurationData)builder.ReadConfiguration(sectionName);
                Assert.AreEqual(myData.ToString(), data.ToString());
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:28,代码来源:ConfigurationBuilderFixture.cs

示例3: ReadWriteNoTransformerTest

 public void ReadWriteNoTransformerTest()
 {
     string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
     using (ConfigurationBuilder builder = new ConfigurationBuilder(configFile))
     {
         XmlNode writeData = SerializeData(data);
         builder.WriteConfiguration(noTransformerSection, writeData);
         XmlNode readData = builder.ReadConfiguration(noTransformerSection) as XmlNode;
         Assert.IsNotNull(readData);
         Assert.AreEqual(writeData.OuterXml, readData.OuterXml);
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:12,代码来源:ConfigurationBuilderFixture.cs

示例4: NoConfigFileTest

 public void NoConfigFileTest()
 {
     using (ConfigurationBuilder builder = new ConfigurationBuilder("c:\\mynonexistentfile.config"))
     {
         builder.ReadConfiguration("config");
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:7,代码来源:ConfigurationBuilderFixture.cs

示例5: MissingSectionProducesCorrectExceptionMessage

 public void MissingSectionProducesCorrectExceptionMessage()
 {
     string file = Path.GetFullPath("MissingMetaDataConfigTest.xml");
     using(ConfigurationBuilder builder = new ConfigurationBuilder(file))
     {
         builder.ReadConfiguration("MySection");
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:8,代码来源:ConfigurationBuilderFixture.cs

示例6: InMemoryInvalidSectionTest

 public void InMemoryInvalidSectionTest()
 {
     ConfigurationDictionary dictionary = new ConfigurationDictionary();
     using (ConfigurationBuilder builder = new ConfigurationBuilder(dictionary))
     {
         builder.ReadConfiguration("invalidSection");
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:8,代码来源:ConfigurationBuilderFixture.cs

示例7: InMemoryConfigurationManagerTest

 public void InMemoryConfigurationManagerTest()
 {
     ConfigurationDictionary dictionary = new ConfigurationDictionary();
     object configurationData = new object();
     dictionary.Add("mySection", configurationData);
     using (ConfigurationBuilder builder = new ConfigurationBuilder(dictionary))
     {
         object actual = builder.ReadConfiguration("mySection");
         Assert.AreSame(configurationData, actual);
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:11,代码来源:ConfigurationBuilderFixture.cs

示例8: ClearCacheTest

 public void ClearCacheTest()
 {
     using (ConfigurationBuilder builder = new ConfigurationBuilder(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile))
     {
         builder.WriteConfiguration(mockConfigSection, data);
         MockConfigurationData readData = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
         MockConfigurationData readData2 = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
         Assert.AreSame(readData, readData2);
         builder.ClearSectionCache();
         readData2 = builder.ReadConfiguration(mockConfigSection) as MockConfigurationData;
         Assert.IsFalse(Object.Equals(readData, readData2));
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:13,代码来源:ConfigurationBuilderFixture.cs


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