本文整理汇总了C#中IConfiguration.GetChild方法的典型用法代码示例。如果您正苦于以下问题:C# IConfiguration.GetChild方法的具体用法?C# IConfiguration.GetChild怎么用?C# IConfiguration.GetChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConfiguration
的用法示例。
在下文中一共展示了IConfiguration.GetChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Configure
public void Configure(IConfiguration config)
{
Port = (int) config.GetChild("port", true).GetValue( typeof(int), 2 );
Server = (String) config.GetChild("server", true).GetValue( typeof(String), "nonlocalhost" );
}
示例2: Logger
/// <summary>
/// <para>
/// Creates a new instance of the Logger with setting loaded from the given configuration.
/// </para>
/// <para>
/// New in 3.0.
/// </para>
/// </summary>
/// <param name="configuration">The configuration object to load settings from.</param>
/// <exception cref="ArgumentNullException">If configuration is null.</exception>
/// <exception cref="ConfigException">
/// If any of the configuration settings are missing or are invalid values.
/// </exception>
protected Logger(IConfiguration configuration)
{
Helper.ValidateNotNull(configuration, "configuration");
// load the logger name from configuration (required)
logname = Helper.GetStringAttribute(configuration, LOGGER_NAME, true);
// load the default level from the properties dictionary (optional, default to Level.DEBUG)
defaultLevel = Helper.GetLevelAttribute(configuration, DEFAULT_LEVEL, DEFAULT_LEVEL_VALUE);
// load NamedMessages child configuration
IConfiguration namedMessagesConfig = configuration.GetChild(NAMED_MESSAGES);
namedMessages = new Dictionary<string, NamedMessage>();
// for each child configuration in namedMessagesConfig,
// create a NamedMessage with attributes loaded from configuration and add to namedMessages
if (namedMessagesConfig != null)
{
foreach (IConfiguration child in namedMessagesConfig.Children)
{
AddNamedMessage(child);
}
}
}