Tpm2Lib.ObjectContextManager.GetBestEvictionCandidate C# (CSharp) Method

GetBestEvictionCandidate() private method

Gets the best eviction candidate for entities of given type. May return NULL.
private GetBestEvictionCandidate ( Tbs neededSlot, ObjectContext neededEntities ) : ObjectContext
neededSlot Tbs
neededEntities ObjectContext
return ObjectContext
        internal ObjectContext GetBestEvictionCandidate(Tbs.SlotType neededSlot, ObjectContext[] neededEntities)
        {
            ObjectContext candidate = null;
            foreach (ObjectContext c in ObjectContexts)
            {
                // See if this context is a candidate for eviction
                if (!c.Loaded)
                {
                    continue;
                }
                if (c.TheSlotType != neededSlot)
                {
                    continue;
                }
                // Currently loaded entity of correct type, but is it referenced in this operation?
                if (neededEntities.Contains(c))
                {
                    continue;
                }

                // ObjectContext c is a candidate for removal.  If we don't already
                // have a candidate then see if the new candidate is staler than the old.
                if (candidate == null)
                {
                    candidate = c;
                }
                else
                {
                    if (c.LastUseCount < candidate.LastUseCount)
                    {
                        candidate = c;
                    }
                }
            }
            return candidate;
        }
    }