-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtime
Description
Background and motivation
We already have ArgumentOutOfRangeException.ThrowIfZero.
API Proposal
public class ArgumentOutOfRangeException : ArgumentException
{
public static void ThrowIfZero<T>(T value, [CallerArgumentExpression(nameof(value))] string? paramName = null)
where T : INumberBase<T>
{
if (!T.IsZero(value))
ThrowNotZero(paramName, value);
}
}API Usage
internal sealed class SingleItemReadOnlyList : IList
{
private readonly object? _item;
public SingleItemReadOnlyList(object? item) => _item = item;
public object? this[int index]
{
get
{
ArgumentOutOfRangeException.ThrowIfNotZero(index);
return _item;
}
}
}Alternative Designs
No response
Risks
No response
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Runtime