// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. using System.Collections.Generic; namespace System.Linq { public static partial class EnumerableEx { /// /// Creates a sequence that retries enumerating the source sequence as long as an error occurs. /// /// Source sequence element type. /// Source sequence. /// Sequence concatenating the results of the source sequence as long as an error occurs. public static IEnumerable Retry(this IEnumerable source) { if (source == null) throw new ArgumentNullException(nameof(source)); return new[] { source }.Repeat().Catch(); } /// /// Creates a sequence that retries enumerating the source sequence as long as an error occurs, with the specified /// maximum number of retries. /// /// Source sequence element type. /// Source sequence. /// Maximum number of retries. /// Sequence concatenating the results of the source sequence as long as an error occurs. public static IEnumerable Retry(this IEnumerable source, int retryCount) { if (source == null) throw new ArgumentNullException(nameof(source)); if (retryCount < 0) throw new ArgumentOutOfRangeException(nameof(retryCount)); return new[] { source }.Repeat(retryCount).Catch(); } } }