【发布时间】:2014-04-15 15:01:40
【问题描述】:
我正在尝试从DirectoryEntry 读取属性。
不幸的是,并非所有记录都有employeeNumber 属性,所以我需要检查它是否存在。
我已经试过了:
a == one DirectoryEntry record
a.GetType().GetProperty("employeeNumber")==null //always returns true
String.IsNullOrWhiteSpace(a.Properties["employeeNumber"].ToString()) //exception
我还能尝试什么?
【问题讨论】:
-
属性通常用 PascalCasing 编写,而不是 camelCasing。您的财产是如何定义的?
-
@OndrejJanacek 在我的案例中,属性是 camelCase
-
你能试试
bool doesExist = a.Properties.Contains("employeeNumber");吗?
标签: c#