moq 4.18.0 不允许我使用 Castle.core.internal 中的 list.IsNullOrEmpty()

Muh*_*zar 3 .net c# moq

当我将单元测试项目更新到 moq 4.18.0 或更高版本时,出现以下异常 Could not load type 'Castle.Core.Internal.CollectionExtensions'IsNullOrEmpty在我的服务类中,我使用Castle.core.internal 中的静态方法。对于低于 4.18.0 的最小起订量版本,我没有遇到此问题。

现在解决问题我只是创建自己的内部IsNullOrEmpty方法。

知道如何解决最小起订量的此异常吗?

Pet*_*ala 5

正如Ralf所说,该产品CollectionExtensions已从包装中取出。

IsNullOrEmpty这样实现的:

public static bool IsNullOrEmpty(this IEnumerable @this)
{
    return @this == null || @this.GetEnumerator().MoveNext() == false;
}
Run Code Online (Sandbox Code Playgroud)

但你也可以这样实现

public static bool IsNullOrEmpty(this IEnumerable @this)
    => !(@this?.GetEnumerator().MoveNext() ?? false);
Run Code Online (Sandbox Code Playgroud)