<PackageReference Include="NUnit" Version="4.4.0-beta.2.1" />

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 { [NullableContext(1)] [Nullable(0)] internal static class ConstraintUtils { public static T RequireActual<[Nullable(2)] T>([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>([Nullable(2)] [NotNull] object actual, string paramName) { return RequireActual<T>(actual, paramName, false); } } }