CountZeroConstraint
CountZeroConstraint tests whether an instance has a property .Count with value zero.
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace NUnit.Framework.Constraints
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class CountZeroConstraint : Constraint
{
private const string CountPropertyName = "Count";
public override string Description => "<empty>";
public static bool HasCountProperty(Type type)
{
return type.GetProperty("Count")?.PropertyType == typeof(int);
}
public override ConstraintResult ApplyTo<[System.Runtime.CompilerServices.Nullable(2)] TActual>(TActual actual)
{
ref TActual reference = ref actual;
TActual val = default(TActual);
object obj;
if (val == null) {
val = reference;
ref reference = ref val;
if (val == null) {
obj = null;
goto IL_003b;
}
}
obj = reference.GetType().GetProperty("Count");
goto IL_003b;
IL_003b:
int? nullable = (int?)((PropertyInfo)obj)?.GetValue((object)actual, (object[])null);
object actualValue = actual;
int? nullable2 = nullable;
int num = 0;
return new ConstraintResult(this, actualValue, (nullable2.GetValueOrDefault() == num) & nullable2.HasValue);
}
public CountZeroConstraint()
: base(Array.Empty<object>())
{
}
}
}