public static IEnumerable <object> GetUsersBySearchKey(string key) { var returnValue = new List <object>(); if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", "SearchKey can not be null or empty!"); } var searchResult = UserInfoHelper.DomainSearch(key); foreach (SearchResult item in searchResult) { dynamic obj = new ExpandoObject(); IDictionary <string, object> dic = obj; foreach (var propertyName in item.Properties.PropertyNames) { dic.Add(propertyName.ToString(), GetProperty(item, propertyName.ToString())); } returnValue.Add(obj); } return(returnValue); }
public static string GetUserName(string key) { string returnValue = ""; if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", "SearchKey can not be null or empty!"); } var searchResult = UserInfoHelper.DomainSearch(key); foreach (SearchResult item in searchResult) { dynamic obj = new ExpandoObject(); foreach (var propertyName in item.Properties.PropertyNames) { if (propertyName.ToString() == "cn") { returnValue = GetProperty(item, propertyName.ToString()); break; } } } return(returnValue); }