Skip to content

Commit

Permalink
Update ReflectionHelpers.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Oct 7, 2023
1 parent 43e263d commit f98fdd8
Showing 1 changed file with 7 additions and 23 deletions.
30 changes: 7 additions & 23 deletions src/Verify/Serialization/ReflectionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<>),
Expand Down

0 comments on commit f98fdd8

Please sign in to comment.