Answers for "c# check if type implements interface"

C#
2

c# check if type implements interface

typeof(IMyInterface).IsAssignableFrom(typeof(MyType))
  // or
typeof(MyType).GetInterfaces().Contains(typeof(IMyInterface))
  // or for a generic interface, it’s a bit different:
typeof(MyType).GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMyInterface<>)
Posted by: Guest on April-21-2020

Code answers related to "c# check if type implements interface"

C# Answers by Framework

Browse Popular Code Answers by Language