public virtual LdapEntry next()
{
if (completed && (entryIndex >= entryCount) && (referenceIndex >= referenceCount))
{
throw new System.ArgumentOutOfRangeException("LdapSearchResults.next() no more results");
}
// Check if the enumeration is empty and must be reloaded
resetVectors();
System.Object element = null;
// Check for Search References & deliver to app as they come in
// We only get here if not following referrals/references
if (referenceIndex < referenceCount)
{
System.String[] refs = (System.String[]) (references[referenceIndex++]);
LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERENCE_NOFOLLOW);
rex.setReferrals(refs);
throw rex;
}
else if (entryIndex < entryCount)
{
// Check for Search Entries and the Search Result
element = entries[entryIndex++];
if (element is LdapResponse)
{
// Search done w/bad status
if (((LdapResponse) element).hasException())
{
LdapResponse lr = (LdapResponse) element;
ReferralInfo ri = lr.ActiveReferral;
if (ri != null)
{
// Error attempting to follow a search continuation reference
LdapReferralException rex = new LdapReferralException(ExceptionMessages.REFERENCE_ERROR, lr.Exception);
rex.setReferrals(ri.ReferralList);
rex.FailedReferral = ri.ReferralUrl.ToString();
throw rex;
}
}
// Throw an exception if not success
((LdapResponse) element).chkResultCode();
}
else if (element is LdapException)
{
throw (LdapException) element;
}
}
else
{
// If not a Search Entry, Search Result, or search continuation
// we are very confused.
// LdapSearchResults.next(): No entry found & request is not complete
throw new LdapException(ExceptionMessages.REFERRAL_LOCAL, new System.Object[]{"next"}, LdapException.LOCAL_ERROR, (System.String) null);
}
return (LdapEntry) element;
}