private static Type[] GetTypesPrefilteredByAssembly(string assemblyName, Func<Type, bool> predicate)
{
InitializeTypes();
// IMPORTANT NOTE!!!! DON'T USE LOGGING IN THE CODE BELOW BECAUSE IT MIGHT CAUSE DEADLOCK (BatchLogListener will load
// async stuff which can deadlock). Keep it simple without calls to other code. Do any type initialization *outside*
// the lock and make sure not to make calls to other methods
lock (_lockObject)
{
Dictionary<string, Type> typeSource = null;
if (!string.IsNullOrWhiteSpace(assemblyName))
{
_typesByAssembly.TryGetValue(assemblyName, out typeSource);
}
else
{
typeSource = _typesWithAssembly;
}
if (typeSource == null)
{
return new Type[] { };
}
int retryCount = 3;
while (retryCount > 0)
{
retryCount--;
try
{
if (predicate != null)
{
return typeSource.Values.Where(predicate).ToArray();
}
return typeSource.Values.ToArray();
}
catch (Exception)
{
}
}
return new Type[] { };
}
// IMPORTANT NOTE: READ NOTE ABOVE BEFORE EDITING THIS METHOD!!!!
}