【发布时间】:2013-09-01 12:48:03
【问题描述】:
我现在正在研究一些关于注册表的东西。
我检查了System.Security.AccessControl 中的枚举RegistryRights。
public enum RegistryRights
{
QueryValues = 1,
SetValue = 2,
CreateSubKey = 4,
EnumerateSubKeys = 8,
Notify = 16,
CreateLink = 32,
Delete = 65536,
ReadPermissions = 131072,
WriteKey = 131078,
ExecuteKey = 131097,
ReadKey = 131097,
ChangePermissions = 262144,
TakeOwnership = 524288,
FullControl = 983103,
}
这个枚举是按位的,而且我知道枚举可以包含重复值。 我试图通过这段代码遍历枚举:
foreach (System.Security.AccessControl.RegistryRights regItem in Enum.GetValues(typeof(System.Security.AccessControl.RegistryRights)))
{
System.Diagnostics.Debug.WriteLine(regItem.ToString() + " " + ((int)regItem).ToString());
}
Enum.GetName(typeof(RegistryRights),regItem) 也返回相同的键名。
我得到的输出是:
QueryValues 1
SetValue 2
CreateSubKey 4
EnumerateSubKeys 8
Notify 16
CreateLink 32
Delete 65536
ReadPermissions 131072
WriteKey 131078
ReadKey 131097
ReadKey 131097
ChangePermissions 262144
TakeOwnership 524288
FullControl 983103
谁能告诉我为什么我会得到重复的密钥?(“ReadKey”而不是“ExecuteKey”) 如何我可以强制它将 int 转换为 value 的第二个键? 以及为什么 ToString 不返回真正的键值?
【问题讨论】: