本文整理汇总了C#中ConfigurationSection类的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationSection类的具体用法?C# ConfigurationSection怎么用?C# ConfigurationSection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationSection类属于命名空间,在下文中一共展示了ConfigurationSection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start(ConfigurationSection configuration) {
_tokenDistributor = new System.Timers.Timer();
_tokenDistributor.Elapsed += new System.Timers.ElapsedEventHandler(TokenDistributor_Elapsed);
_tokenDistributor.Interval = _interval;
_tokenDistributor.AutoReset = true;
_tokenDistributor.Enabled = true;
}
示例2: Parse
public IEnumerable<ConfigurationEntry> Parse(string data)
{
ConfigurationSection currentSection = null;
foreach (var line in data.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries))
{
var sectionMatch = _configurationSectionRegex.Match(line);
if (sectionMatch.Success)
{
if (currentSection != null)
yield return currentSection;
currentSection = new ConfigurationSection
{
Type = sectionMatch.Groups["type"].Value,
Name = sectionMatch.Groups["name"].Success ? sectionMatch.Groups["name"].Value : string.Empty
};
continue;
}
var lineMatch = _configurationLineRegex.Match(line);
if (lineMatch.Success)
{
var configLine = new ConfigurationLine
{
Name = lineMatch.Groups["name"].Value,
Value = lineMatch.Groups["value"].Value
};
if (currentSection != null)
currentSection.Lines.Add(configLine);
else
yield return configLine;
}
}
if (currentSection != null)
yield return currentSection;
}
示例3: CanRemoveAddedValue
public void CanRemoveAddedValue()
{
var section = new ConfigurationSection( SectionName );
section.Set( Key, Value );
bool success = section.Remove( Key );
Assert.True( success );
}
示例4: CanReadAddedValue
public void CanReadAddedValue()
{
var section = new ConfigurationSection( SectionName );
section.Set( Key, Value );
var value = section.Get<string>( "key" );
Assert.Equal( Value, value );
}
示例5: GetConfigurationSource
protected static ConfigurationSourceBaseImpl GetConfigurationSource()
{
var section = new ConfigurationSection( SectionName );
var source = new ConfigurationSourceBaseImpl {section};
section.Set( Key, Value );
return source;
}
示例6: GetInstance
public static ConfigurationSection GetInstance()
{
if (instance == null)
{
lock (typeof(ConfigurationSection))
{
try
{
#pragma warning disable 618
instance = (ConfigurationSection)ConfigurationSettings.GetConfig("Platform/VirtualFileSystem/Multimedia/Configuration");
#pragma warning restore 618
}
catch (Exception e)
{
throw e.InnerException;
}
if (instance == null)
{
instance = new ConfigurationSection();
}
}
}
return instance;
}
示例7: CanGetAndSetEnumFlagValues
public void CanGetAndSetEnumFlagValues()
{
const OptionsEnum all = ( OptionsEnum.A | OptionsEnum.B | OptionsEnum.C );
var section = new ConfigurationSection( SectionName );
section.Set( Key, all );
var fromSection = section.Get<OptionsEnum>( Key );
Assert.AreEqual( all, fromSection );
}
示例8: CanGetAndSetEnumValues
public void CanGetAndSetEnumValues()
{
const OSEnum value = OSEnum.Win2k;
var section = new ConfigurationSection( SectionName );
section.Set( Key, value );
var fromSection = section.Get<OSEnum>( Key );
Assert.AreEqual( value, fromSection );
}
示例9: CanReadAddedValueWithTryGet
public void CanReadAddedValueWithTryGet()
{
var section = new ConfigurationSection( SectionName );
section.Set( Key, Value );
string value;
bool found = section.TryGet( "key", out value );
Assert.True( found );
Assert.Equal( Value, value );
}
示例10: AddingNewSectionOverridesKeys
public void AddingNewSectionOverridesKeys()
{
ConfigurationSourceBaseImpl source = GetConfigurationSource();
var section = new ConfigurationSection( SectionName );
section.Set( Key, Key );
Assert.Equal( Value, source.Sections[SectionName].Get<string>( Key ) );
source.Add( section );
Assert.Equal( Key, source.Sections[SectionName].Get<string>( Key ) );
}
示例11: MergingWithCollectionOverwritesExistingKeys
public void MergingWithCollectionOverwritesExistingKeys()
{
ConfigurationSourceBaseImpl source = GetConfigurationSource();
var section = new ConfigurationSection( SectionName );
section.Set( Key, Key );
var source2 = new ConfigurationSourceBaseImpl {section};
Assert.Equal( Value, source.Sections[SectionName].Get<string>( Key ) );
source.Merge( new[] {source2} );
Assert.Equal( Key, source.Sections[SectionName].Get<string>( Key ) );
}
示例12: MergingWithCollectionAddsConfigurationSection
public void MergingWithCollectionAddsConfigurationSection()
{
ConfigurationSourceBaseImpl source = GetConfigurationSource();
const string sectionName = SectionName + Key;
var section = new ConfigurationSection( sectionName );
section.Set( Key, Key );
var source2 = new ConfigurationSourceBaseImpl {section};
source.Merge( new[] {source2} );
Assert.Contains( section, source );
}
示例13: GetSingleSection
public static IConfigurationSection GetSingleSection()
{
IConfigurationSection section = new ConfigurationSection( "Default" );
section.Set( "a", "a" );
section.Set( "b", "b" );
section.Set( "c", "c" );
section.Set( "d", "d" );
section.Set( "e", "e" );
return section;
}
示例14: GetTwoSections
public static IEnumerable<IConfigurationSection> GetTwoSections()
{
IConfigurationSection section = new ConfigurationSection( "Default" );
section.Set( "a", "a" );
section.Set( "b", "b" );
IConfigurationSection section2 = new ConfigurationSection( "Default2" );
section2.Set( "c", "c" );
section2.Set( "d", "d" );
section2.Set( "e", "e" );
return new[] { section, section2 };
}
示例15: EnumeratorGivesKeysAndValues
public void EnumeratorGivesKeysAndValues()
{
var section = new ConfigurationSection( SectionName );
section.Set( Key, Value );
int count = 0;
foreach ( KeyValuePair<string, string> pair in section )
{
Assert.Equal( Key, pair.Key );
Assert.Equal( Value, pair.Value );
count++;
}
Assert.Equal( 1, count );
}