22 lines
860 B
C#
22 lines
860 B
C#
using System;
|
|
using System.Linq;
|
|
namespace ln.types.reflection
|
|
{
|
|
public static class TypeExtensions
|
|
{
|
|
|
|
public static bool HasGenericInterface<T>(this Type type) => HasGenericInterface(type, typeof(T).GetGenericTypeDefinition());
|
|
public static bool HasGenericInterface(this Type type, Type genericInterfaceType)
|
|
{
|
|
return type.GetInterfaces().Any(x => x.IsGenericType && x.GetGenericTypeDefinition() == genericInterfaceType);
|
|
}
|
|
|
|
public static Type GetGenericInterface<T>(this Type type) => GetGenericInterface(type, typeof(T).GetGenericTypeDefinition());
|
|
public static Type GetGenericInterface(this Type type, Type genericInterfaceType)
|
|
{
|
|
return type.GetInterfaces().First(x => x.IsGenericType && x.GetGenericTypeDefinition() == genericInterfaceType);
|
|
}
|
|
|
|
}
|
|
}
|