是否可以在 AutoFixture SemanticComparison 中为指定类型设置自定义比较器

Is it possible in AutoFixture SemanticComparison to set custom comparer for specified type

是否可以在 AutoFixture SemanticComparison 中为指定的 属性 对象或指定类型设置自定义比较器。

例如,您需要比较 属性 类型为 DateTime 的对象。您想使用 Likenes 比较它们,但您希望比较的精度能够丢弃毫秒级别的差异(可能在从数据库中检索 DateTime 后丢失了精度)。

您可以使用 Likeness(流利)API 的 EqualsWhen 成员来做到这一点。

Here 是一个非常相似的例子。