<PackageReference Include="NUnit" Version="4.4.0" />

ConstraintUtils

static class ConstraintUtils
Provides methods to support consistent checking in constraints.
using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace NUnit.Framework.Internal { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] internal static class ConstraintUtils { public static T RequireActual<[System.Runtime.CompilerServices.Nullable(2)] T>([System.Runtime.CompilerServices.Nullable(2)] object actual, string paramName, bool allowNull) { if (TypeHelper.TryCast(actual, out T value) && (allowNull || value != null)) return value; string str = (actual == null) ? "null" : actual.GetType().Name; throw new ArgumentException("Expected: " + typeof(T).Name + " But was: " + str, paramName); } public static T RequireActual<T>([System.Runtime.CompilerServices.Nullable(2)] [NotNull] object actual, string paramName) { return RequireActual<T>(actual, paramName, false); } } }