检测活动目录对象的正确方法是属于用户还是组?

Correct way to detect active directory object is belong to user or group?

检测活动目录对象属于组或用户的正确方法是什么?这是我在 C# 中的处理方式:

foreach (SearchResult sr in src)
{
   if (sr.Properties["objectclass"].Contains("person") && sr.Properties["objectclass"].Contains("user"))
   {
      // USER ?
   }
   if (sr.Properties["objectclass"].Contains("group"))
   {
      // GROUP ?
   }
}
if (sr != null)
{
    if(sr.Properties["objectCategory"] != null)
    {
       // objectType will be "Person" or "Group" (or something else entirely)
       string objectType = sr.Properties["objectCategory"][0].ToString();
       if (objectType == "Person")
       { 
          //It's a user
       }
       if (objectType == "Group")
       { 
          //It's a Group
       }
    }
}

检索自:How to determine the type (AD User vs. AD Group) of an account?