本文整理汇总了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());
}
}
示例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());
}
}
示例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);
}
}
示例4: NoConfigFileTest
public void NoConfigFileTest()
{
using (ConfigurationBuilder builder = new ConfigurationBuilder("c:\\mynonexistentfile.config"))
{
builder.ReadConfiguration("config");
}
}
示例5: MissingSectionProducesCorrectExceptionMessage
public void MissingSectionProducesCorrectExceptionMessage()
{
string file = Path.GetFullPath("MissingMetaDataConfigTest.xml");
using(ConfigurationBuilder builder = new ConfigurationBuilder(file))
{
builder.ReadConfiguration("MySection");
}
}
示例6: InMemoryInvalidSectionTest
public void InMemoryInvalidSectionTest()
{
ConfigurationDictionary dictionary = new ConfigurationDictionary();
using (ConfigurationBuilder builder = new ConfigurationBuilder(dictionary))
{
builder.ReadConfiguration("invalidSection");
}
}
示例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);
}
}
示例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));
}
}