Skip to content

Instantly share code, notes, and snippets.

@mhinze
Created August 4, 2009 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhinze/161389 to your computer and use it in GitHub Desktop.
Save mhinze/161389 to your computer and use it in GitHub Desktop.
public static bool IsSubclassOfOpenGeneric(this Type type, Type generic)
{
while (type != typeof(object))
{
var current = type.IsGenericType ? type.GetGenericTypeDefinition() : type;
if (generic == current)
{
return true;
}
type = type.BaseType;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment