Я где-то видел такой код.
В идеале я хотел бы, чтобы такой цикл соответствовал этому типу события Func.
public static event Func<RecentDirectories, DirectoryInfo, Exception, bool> ContinueOnExceptionEvent;
/// <summary>
/// Determine if the loop should continue on a general exception not already handled
/// in the loop's catch statement.
/// </summary>
/// <param name="dir"></param>
/// <param name="e"></param>
/// <returns>True continues loop, false rethrows the exception</returns>
protected virtual bool TryContinueOnException(DirectoryInfo dir, Exception ex)
{
if (!Aborted) // check if thread aborted before doing event
{
if (null != ContinueOnExceptionEvent)
{
// foreach line doesn't compile because
// ContinueOnExceptionEvent doesn't have a GetEnumerator()
foreach (var e in ContinueOnExceptionEvent)
{
if (e(this, dir, ex))
{
return true;
}
}
}
}
return false;
}
Как мне получить foreach для получения всех событий и итерации по ним?