我觉得我在这里失去了理智。我正在用一个人的姓名查询AD以获取他们的AD ID和电子邮件地址。在设计时,没有EmailAddress属性,但在运行时它存在。如果在设计时对其进行编码,如果无法编译,那么我在运行时如何访问此EmailAddress?
private Dictionary<string, string> GetActiveDirectoryID(string firstName, string lastName)
{
var result = new Dictionary<string, string>();
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// query AD by first and last name
UserPrincipal qbeUser = new UserPrincipal(ctx);
qbeUser.GivenName = firstName;
qbeUser.Surname = lastName;
PrincipalSearcher srch = new PrincipalSearcher(qbeUser);
var found = srch.FindOne();
result.Add("id", found.SamAccountName);
result.Add("email", found.EmailAddress); //??
return result;
}