简体   繁体   中英

moq 4.18.0 doest allow me to use list.IsNullOrEmpty() from Castle.core.internal

when i update my unit test project to moq 4.18.0 or above, i get the following exception Could not load type 'Castle.Core.Internal.CollectionExtensions' . In my service class im using the static method IsNullOrEmpty from Castle.core.internal. Im not getting this issue for moq versions below 4.18.0.

the resolve the issue for now I'm just creating my own internal IsNullOrEmpty method.

Any Idea how to solve this exception from moq?

As it was stated by Ralf the CollectionExtensions has been removed from the package.

The IsNullOrEmpty was implemented like this:

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

But you can implement like this as well

public static bool IsNullOrEmpty(this IEnumerable @this)
    => !(@this?.GetEnumerator().MoveNext() ?? false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM