internal object Lookup(string lookupKey) {
if (lookupKey==null) {
return null;
}
object mostSpecificMatch = null;
int longestMatchPrefix = 0;
int prefixLen;
lock (m_Store) {
//
// readers don't need to be locked, but we lock() because:
// "The enumerator does not have exclusive access to the collection.
//
// When an enumerator is instantiated, it takes a snapshot of the current state
// of the collection. If changes are made to the collection, such as adding,
// modifying or deleting elements, the snapshot gets out of sync and the
// enumerator throws an InvalidOperationException. Two enumerators instantiated
// from the same collection at the same time can have different snapshots of the
// collection."
//
// enumerate through every credential in the cache
//
string prefix;
foreach (DictionaryEntry entry in m_Store) {
prefix = (string)entry.Key;
if (lookupKey.StartsWith(prefix)) {
prefixLen = prefix.Length;
//
// check if the match is better than the current-most-specific match
//
if (prefixLen>longestMatchPrefix) {
//
// Yes-- update the information about currently preferred match
//
longestMatchPrefix = prefixLen;
mostSpecificMatch = entry.Value;
}
}
}
}
return mostSpecificMatch;
}