Skip to content

Instantly share code, notes, and snippets.

@q42jaap

q42jaap/gist:2936304

Created Jun 15, 2012
Embed
What would you like to do?
GetGenericArgumentsForBaseType
static Type[] GetGenericArgumentsForBaseType(Type givenType, Type genericType)
{
if (genericType.IsInterface)
{
var interfaceTypes = givenType.GetInterfaces();
foreach (var it in interfaceTypes)
{
if (it.IsGenericType && it.GetGenericTypeDefinition() == genericType)
return it.GetGenericArguments();
}
}
else
{
Type baseType = givenType;
while (baseType != null)
{
if (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == genericType)
return baseType.GetGenericArguments();
baseType = baseType.BaseType;
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.