Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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<>)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #type #implements #interface
ADD COMMENT
Topic
Name
3+3 =