public Principal FindOne() { Principal current; this.CheckDisposed(); PrincipalSearchResult <Principal> principals = this.FindAll(true); using (principals) { FindResultEnumerator <Principal> enumerator = (FindResultEnumerator <Principal>)principals.GetEnumerator(); if (!enumerator.MoveNext()) { current = null; } else { current = enumerator.Current; } } return(current); }
public Principal FindOne() { GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalSearcher", "Entering FindOne()"); CheckDisposed(); using (PrincipalSearchResult <Principal> fr = FindAll(true)) { FindResultEnumerator <Principal> fre = (FindResultEnumerator <Principal>)fr.GetEnumerator(); // If there's (at least) one result, return it. Else return null. if (fre.MoveNext()) { GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalSearcher", "FindOne(): found a principal"); return((Principal)fre.Current); } else { GlobalDebug.WriteLineIf(GlobalDebug.Info, "PrincipalSearcher", "FindOne(): found no principal"); return(null); } } }