How to check if a type implements a specific interface using reflection in C#
Hello everyone! I'm a beginner C# developer and I'm having an issue with reflection. I have a library where users can pass their own classes. I need to dynamically check if the passed type implements a specific interface so I can call its methods later.
Here's an example: there is an IPlugin interface and several classes that implement it. I get the type via Type.GetType("SomeClass") and want to check if this class implements IPlugin. I tried using Type.IsAssignableFrom, but I'm confused about which type to pass. I also saw the GetInterfaces() method, but I'm not sure if that's the best solution.
Here's simplified code:
```csharp
public interface IPlugin {
void Execute();
}
public class MyPlugin : IPlugin {
public void Execute() { Console.WriteLine("Hello"); }
}
// At runtime I