我正在尝试从中读取属性DirectoryEntry
。
不幸的是并非所有记录都有employeeNumber
属性,所以我需要检查它是否存在。
我已经尝试过:
a == one DirectoryEntry record
a.GetType().GetProperty("employeeNumber")==null //always returns true
String.IsNullOrWhiteSpace(a.Properties["employeeNumber"].ToString()) //exception
我还能尝试什么?
你可以这样尝试:
OBJECT.GetType().GetProperty("PROPERTY") != null
所以在你的代码中它会是这样的:
var a = one DirectoryEntry record;
var pi = a.GetType().GetProperty("employeeNumber");
var value = pi.GetValue(a, null);
EDIT:-
尝试这个:
bool x = a.Properties.Contains("employeeNumber");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)