Skip to content

Instantly share code, notes, and snippets.

@lakario
Created December 22, 2016 15:10
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 lakario/4cf7f7800c37480fb8568328055d99cd to your computer and use it in GitHub Desktop.
Save lakario/4cf7f7800c37480fb8568328055d99cd to your computer and use it in GitHub Desktop.
.NET doesn't provide a method to reflect the immediate interface ancestors of a given type, this method accomplishes that.
private IEnumerable<Type> GetClosestInterfaces(Type type)
{
IEnumerable<Type> interfaces = type.GetInterfaces();
var parents = interfaces.Except(
interfaces.SelectMany(x => x.GetInterfaces()).Intersect(interfaces));
return parents;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment