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

PropertyExistsConstraint

PropertyExistsConstraint tests that a named property exists on the object provided through Match. Originally, PropertyConstraint provided this feature in addition to making optional tests on the value of the property. The two constraints are now separate.
using System; using System.Reflection; namespace NUnit.Framework.Constraints { public class PropertyExistsConstraint : Constraint { private readonly string name; private Type actualType; public override string Description => "property " + name; public PropertyExistsConstraint(string name) : base(name) { this.name = name; } public override ConstraintResult ApplyTo<TActual>(TActual actual) { Guard.ArgumentNotNull(actual, "actual"); actualType = (actual as Type); if (actualType == (Type)null) actualType = actual.GetType(); PropertyInfo property = actualType.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); return new ConstraintResult(this, actualType, property != (PropertyInfo)null); } protected override string GetStringRepresentation() { return $"""{name}"""; } } }