Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type.GetInterfaces() workaround for .NET Standard 1.x

.NET Core 1.1 supports Type.GetInterfaces() method which provides a list of the interfaces implemented on a given type. Unfortunately, Type.GetInterfaces() is not yet available in .NET Standard 1.x.

The good news is that it is supposed to included in .NET Standard 2.0.

In the meantime, does anyone know of a workaround I can use to get the list of interfaces on a type and/or the list of classes which implement a given interface in .NET Standard 1.x?

Many thanks!

like image 713
Anthony Gatlin Avatar asked May 25 '17 22:05

Anthony Gatlin


Video Answer


1 Answers

This should do the trick. GetTypeInfo() is an extension method in the System.Reflection namespace, part of the InstrospectionExtensions.

using System.Reflection;
var interfaces = typeof({SOME_TYPE}).GetTypeInfo().GetInterfaces();
like image 192
Roberto Hernandez Avatar answered Nov 03 '22 02:11

Roberto Hernandez