我认为您需要使用UInt32 作为您的枚举类型GroupType,如下所示:
[Flags]
public enum GroupType : uint
{
BUILTIN_LOCAL_GROUP = 0x00000001,
ACCOUNT_GROUP = 0x00000002,
RESOURCE_GROUP = 0x00000004,
UNIVERSAL_GROUP = 0x00000008,
APP_BASIC_GROUP = 0x00000010,
APP_QUERY_GROUP = 0x00000020,
SECURITY_ENABLED = 0x80000000
}
如果这能解决您的问题,请告诉我。
编辑:好的,我不确定Entry 是您创建的对象,还是 Active Directory API 的一部分。话虽如此,我在我目前正在处理的项目中快速创建了以下变量,并编译如下:
// I only made it static so I could get my compiler to compile this in something I'm currently
// working on. It's not necessary for it to be static.
static int SECURITY_ENABLED = 0x80000000;
int newValue = SECURITY_ENABLED | 1;
我没有收到任何编译时错误。事实上,再看0x80000000的值,它在Int32的范围内很好。
重新查看上面的代码,究竟在哪一行,你得到错误了吗?我看到了这个可疑代码:
if (groupTypes.Count == 1)
{
var firstFlag = (int) groupTypes[0];
// What is this checking, exactly?
// Is this where the error is occurring?
var longFlag = -(((long) flag) - firstFlag);
if ((longFlag == 0x80000000)) // Extra parentheses here...just a formatting thing
groupTypes.Add(GroupType.SECURITY_ENABLED);
}
也许这段代码可以简化?
public List<GroupType> GetGroupType()
{
var groupTypes = new List<GroupType>();
var flag = (GroupType) this.Entry.Properties["groupType"].Value;
if (flag & GroupType.ACCOUNT_GROUP > 0)
groupTypes.Add(GroupType.ACCOUNT_GROUP;
else if (flag & GroupType.APP_BASIC_GROUP > 0)
groupTypes.Add(GroupType.APP_BASIC_GROUP);
// ... Other else if ad nauseum ...
else if (flag & GroupType.SERUCITY_ENABLED > 0)
groupTypes.Add(GroupType.SECURITY_ENABLED);
return groupTypes;
}
如果您出于某种原因确实需要ArrayList(),那么您可以直接使用return groupTypes.ToArray<int>();
HTH。