本文整理汇总了C#中IConfiguration.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# IConfiguration.GetProperty方法的具体用法?C# IConfiguration.GetProperty怎么用?C# IConfiguration.GetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConfiguration
的用法示例。
在下文中一共展示了IConfiguration.GetProperty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConcurrentDictionaryConfiguration
/// <summary>
/// Create an instance by copying the properties from an existing Configuration.
/// Future changes to the Configuration passed in will not be reflected in this
/// object.
/// </summary>
/// <param name="config">Configuration to be copied</param>
public ConcurrentDictionaryConfiguration(IConfiguration config)
: this()
{
foreach (var key in config.Keys)
{
m_Properties[key] = config.GetProperty(key);
}
}
示例2: AddOrChangeProperty
/// <summary>
/// Add or update the property in the underlying config depending on if it exists
/// </summary>
/// <param name="name"></param>
/// <param name="newValue"></param>
/// <param name="config"></param>
public void AddOrChangeProperty(string name, object newValue, IConfiguration config)
{
// We do not want to abort the operation due to failed validation on one property
try
{
if (!config.ContainsKey(name))
{
m_Log.DebugFormat("Adding property key [{0}], value [{1}]", name, newValue);
config.AddProperty(name, newValue);
return;
}
var oldValue = config.GetProperty(name);
if (newValue != null)
{
object newValueArray;
if (oldValue is IList && config.ListDelimiter != '\0')
{
newValueArray = new ArrayList();
var values = ((string)newValue).Split(config.ListDelimiter).Select(v => v.Trim()).Where(v => v.Length != 0);
foreach (var value in values)
{
((IList)newValueArray).Add(value);
}
}
else
{
newValueArray = newValue;
}
if (!ObjectUtils.AreEqual(newValueArray, oldValue))
{
m_Log.DebugFormat("Updating property key [{0}], value [{1}]", name, newValue);
config.SetProperty(name, newValue);
}
}
else if (oldValue != null)
{
m_Log.DebugFormat("nulling out property key [{0}]", name);
config.SetProperty(name, null);
}
}
catch (ValidationException e)
{
m_Log.Warn("Validation failed for property " + name, e);
}
}
示例3: AppendListProperty
/// <summary>
/// Adds the value of a property to the given list.
/// This method is used by <see cref="GetList"/> for gathering property values from the child configurations.
/// </summary>
/// <param name="dest">The list for collecting the data</param>
/// <param name="config">The configuration to query</param>
/// <param name="key">The key of the property</param>
private static void AppendListProperty(IList dest, IConfiguration config, string key)
{
var value = config.GetProperty(key);
if (value == null)
{
return;
}
if (value is IList)
{
foreach (var item in (IList)value)
{
dest.Add(item);
}
}
else
{
dest.Add(value);
}
}
示例4: TestConfigurationGet
private void TestConfigurationGet(IConfiguration conf)
{
long start = Environment.TickCount;
for (int i = 0; i < 1000000; i++)
{
conf.GetProperty("key" + (i % 100));
}
long duration = Environment.TickCount - start;
Console.WriteLine("get property for " + conf + " took " + duration + " ms");
}