我認爲你需要使用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
。
重新審視上面的代碼,確切地說,你會得到錯誤嗎?我看到這個suspicios代碼:
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。
國旗上有是一個int 0x80000000的適合的單位很好。 – urbanlemur
默認情況下,Int32已簽名。你可以使用UInt32? – fourpastmidnight
Entry.Properties [「groupType」]。Value返回-2147483646。當我嘗試將其轉換爲UINT我得到一個InvalidCastException – wodzu