本文整理汇总了C#中System.Configuration.ConfigurationElement.LockAttributes属性的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationElement.LockAttributes属性的具体用法?C# ConfigurationElement.LockAttributes怎么用?C# ConfigurationElement.LockAttributes使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Configuration.ConfigurationElement
的用法示例。
在下文中一共展示了ConfigurationElement.LockAttributes属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LockAttributes
// Show how to use LockAttributes.
// It locks and unlocks all the urls elements.
static void LockAttributes()
{
try
{
// Get the current configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);
// Get the MyUrls section.
UrlsSection myUrlsSection =
config.GetSection("MyUrls") as UrlsSection;
if (myUrlsSection == null)
{
Console.WriteLine("Failed to load UrlsSection.");
}
else
{
IEnumerator elemEnum =
myUrlsSection.Urls.GetEnumerator();
int i = 0;
while (elemEnum.MoveNext())
{
// Get the current element.
ConfigurationElement element =
myUrlsSection.Urls[i];
// Get the lock attributes collection of
// the current element.
ConfigurationLockCollection lockAttributes =
element.LockAttributes;
// Add or remove the lock on the attributes.
if (lockAttributes.Contains("name"))
lockAttributes.Remove("name");
else
lockAttributes.Add("name");
if (lockAttributes.Contains("url"))
lockAttributes.Remove("url");
else
lockAttributes.Add("url");
if (lockAttributes.Contains("port"))
lockAttributes.Remove("port");
else
lockAttributes.Add("port");
// Get the locket attributes.
string lockedAttributes =
lockAttributes.AttributeList;
Console.WriteLine(
"Element {0} Locked attributes list: {1}",
i.ToString(), lockedAttributes);
i += 1;
config.Save(ConfigurationSaveMode.Full);
}
}
}
catch (ConfigurationErrorsException e)
{
Console.WriteLine("[LockAttributes: {0}]",
e.ToString());
}
}