-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypeExtensions.cs
33 lines (29 loc) · 894 Bytes
/
TypeExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#nullable enable
namespace NServiceBus.Persistence.DynamoDB
{
using System;
static class TypeExtensions
{
public static bool IsAssignableToGenericType(this Type givenType, Type genericType)
{
var interfaceTypes = givenType.GetInterfaces();
foreach (var it in interfaceTypes)
{
if (it.IsGenericType && it.GetGenericTypeDefinition() == genericType)
{
return true;
}
}
if (givenType.IsGenericType && givenType.GetGenericTypeDefinition() == genericType)
{
return true;
}
Type? baseType = givenType.BaseType;
if (baseType == null)
{
return false;
}
return IsAssignableToGenericType(baseType, genericType);
}
}
}