You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Recyclarr.Common/Extensions/TypeExtensions.cs

17 lines
535 B

namespace Recyclarr.Common.Extensions;
public static class TypeExtensions
{
public static bool IsGenericTypeOf(this Type type, Type genericType)
{
return type is {IsGenericType: true} && type.GetGenericTypeDefinition() == genericType;
}
public static bool IsImplementationOf(this Type type, Type collectionType)
{
return
type is {IsInterface: true} && type.IsGenericTypeOf(collectionType) ||
type.GetInterfaces().Any(i => i.IsGenericTypeOf(typeof(ICollection<>)));
}
}