Contracts added to ThrowHelper.

This commit is contained in:
mlemanczyk committed 2023-06-20 00:41:28 +02:00
1 parent 15cac80d2f
commit 85aac1dad6
1 file changed
+18 -4
+18 -4
View File
@@ -1,4 +1,6 @@
namespace Recyclable.Collections
using System.Diagnostics.Contracts;
namespace Recyclable.Collections
{
internal static class ThrowHelper
{
@@ -6,18 +8,30 @@
/// This is a helper method to throw <see cref="InvalidOperationException"/>, thrown when the collection was modified during enumeration.
/// </summary>
/// <exception cref="InvalidOperationException">Always</exception>
public static void ThrowListModifiedException() => throw new InvalidOperationException("Can't move to the next item, because the collection was modified. You must restart the enumeration by calling Reset(), if you want to enumerate the collection again");
public static void ThrowListModifiedException()
{
Contract.EnsuresOnThrow<InvalidOperationException>(false);
throw new InvalidOperationException("Can't move to the next item, because the collection was modified. You must restart the enumeration by calling Reset(), if you want to enumerate the collection again");
}
/// <summary>
/// This is a helper method to throw <see cref="InvalidOperationException"/> with the given message.
/// </summary>
/// <exception cref="InvalidOperationException">Always</exception>
public static void ThrowInvalidOperationException(in string message) => throw new InvalidOperationException(message);
public static void ThrowInvalidOperationException(in string message)
{
Contract.EnsuresOnThrow<InvalidOperationException>(false);
throw new InvalidOperationException(message);
}
/// <summary>
/// This is a helper method to throw <see cref="ArgumentOutOfRangeException"/> with the given message.
/// </summary>
/// <exception cref="ArgumentOutOfRangeException">Always</exception>
public static void ThrowArgumentOutOfRangeException(in string argumentName, in string message) => throw new ArgumentOutOfRangeException(argumentName, message);
public static void ThrowArgumentOutOfRangeException(in string argumentName, in string message)
{
Contract.EnsuresOnThrow<ArgumentOutOfRangeException>(false);
throw new ArgumentOutOfRangeException(argumentName, message);
}
}
}