From f98fdd8956e7fd3c71c92b137c0f70db216b65a5 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Sat, 7 Oct 2023 22:34:50 +1100 Subject: [PATCH] Update ReflectionHelpers.cs --- src/Verify/Serialization/ReflectionHelpers.cs | 30 +++++-------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/Verify/Serialization/ReflectionHelpers.cs b/src/Verify/Serialization/ReflectionHelpers.cs index ecf2679372..2d66d33d43 100644 --- a/src/Verify/Serialization/ReflectionHelpers.cs +++ b/src/Verify/Serialization/ReflectionHelpers.cs @@ -61,15 +61,9 @@ public static Type MemberType(this MemberInfo member) => _ => throw new($"No supported MemberType: {member.MemberType}") }; - public static bool IsEmptyCollectionOrDictionary(this object target) - { - if (TryGetCollectionOrDictionary(target, out var isEmpty, out _)) - { - return isEmpty.Value; - } - - return false; - } + public static bool IsEmptyCollectionOrDictionary(this object target) => + TryGetCollectionOrDictionary(target, out var isEmpty, out _) && + isEmpty.Value; public static bool TryGetCollectionOrDictionary(this object target, [NotNullWhen(true)] out bool? isEmpty, [NotNullWhen(true)] out IEnumerable? enumerable) { @@ -137,24 +131,14 @@ public static bool IsGeneric(this Type type, params Type[] generics) return true; } } - return false; - } - - public static bool IsGeneric(this Type type, Type generic) - { - if (!type.IsGenericType) - { - return false; - } - - if (type.GetGenericTypeDefinition() == generic) - { - return true; - } return false; } + public static bool IsGeneric(this Type type, Type generic) => + type.IsGenericType && + type.GetGenericTypeDefinition() == generic; + static bool ImplementsGenericCollection(this Type type) => type.IsGeneric( typeof(ICollection<>),