// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Diagnostics.CodeAnalysis; namespace CommunityToolkit.Diagnostics; /// /// Helper methods to verify conditions when running code. /// public static partial class Guard { /// /// Helper methods to efficiently throw exceptions. /// private static partial class ThrowHelper { /// /// Throws an when fails. /// /// The item of items in the input instance. /// This method is needed because can't be used as a generic type parameter. [DoesNotReturn] public static void ThrowArgumentExceptionForIsNotEmptyWithSpan(string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(Span).ToTypeString()}) must not be empty.", name); } /// /// Throws an when fails. /// /// The item of items in the input instance. /// This method is needed because can't be used as a generic type parameter. [DoesNotReturn] public static void ThrowArgumentExceptionForIsNotEmptyWithReadOnlySpan(string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(ReadOnlySpan).ToTypeString()}) must not be empty.", name); } /// /// Throws an when (or an overload) fails. /// /// The item of items in the input collection. [DoesNotReturn] public static void ThrowArgumentExceptionForIsNotEmpty(string name) { throw new ArgumentException($"Parameter {AssertString(name)} ({typeof(T).ToTypeString()}) must not be empty.", name); } } }