6
考慮下面的代碼:System.DirectoryServices.AccountManagement.PrincipalCollection - 如何檢查主體是用戶還是組?
GroupPrincipal gp = ... // gets a reference to a group
foreach (var principal in gp.Members)
{
// How can I determine if principle is a user or a group?
}
基本上我想知道的是(基於成員集合),其成員是用戶,哪些是羣體的。根據他們是什麼類型,我需要發射額外的邏輯。
很不錯的解決方案 - 謝謝! –
或使用'is'運算符(例如,var result = principal是UserPrincipal),它可能在內部執行與其中一個選項類似的操作 –