本文整理汇总了C#中IConfiguration.TryGet方法的典型用法代码示例。如果您正苦于以下问题:C# IConfiguration.TryGet方法的具体用法?C# IConfiguration.TryGet怎么用?C# IConfiguration.TryGet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConfiguration
的用法示例。
在下文中一共展示了IConfiguration.TryGet方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
public void Read(IConfiguration configuration)
{
string value;
if (configuration.TryGet("RetryCount", out value))
{
RetryCount = int.Parse(value);
}
if (configuration.TryGet("DefaultAdBlock", out value))
{
DefaultAdBlock = value;
}
var items = new List<AdBlock>();
foreach (var subConfig in configuration.GetSubKeys("AdBlock"))
{
var item = new AdBlock { Name = subConfig.Key };
if (subConfig.Value.TryGet("Origin", out value))
{
item.Origin = value;
}
if (subConfig.Value.TryGet("ProductCode", out value))
{
item.ProductCode = value;
}
items.Add(item);
}
AdBlocks = items.ToDictionary(
item => item.Name,
item => item,
StringComparer.OrdinalIgnoreCase);
}
示例2: Initialize
public void Initialize(IConfiguration configuration)
{
string urls;
if (!configuration.TryGet("server.urls", out urls))
{
urls = "http://+:5000/";
}
foreach (var url in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
string scheme;
string host;
int port;
string path;
if (DeconstructUrl(url, out scheme, out host, out port, out path))
{
Addresses.Add(
new ServerAddress
{
Scheme = scheme,
Host = host,
Port = port,
Path = path
});
}
}
}
示例3: GetString
private string GetString(IConfiguration config, string key)
{
string s;
if (config.TryGet(key, out s))
{
return s;
}
return null;
}
示例4: Initialize
public void Initialize(IConfiguration configuration)
{
string urls;
if (!configuration.TryGet("server.urls", out urls))
{
urls = "http://+:5000/";
}
foreach (var url in urls.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
var address = ServerAddress.FromUrl(url);
if(address != null)
{
Addresses.Add(address);
}
}
}
示例5: Get
private string Get(IConfiguration configuration, string key, string defaultValue)
{
string value;
return configuration.TryGet(key, out value) ? value : defaultValue;
}