Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return the types of interfaces that a class implements C#

Is there a way to get the type of an interface that a class implements. For further explanation of the problem here's what I mean. For example:

public interface ISomeInterface
{

}

public class SomeClass : ISomeInterface
{

}

public class SecondClass
{

    ISomeInterface someclass;

    public SecondClass()
    {
        someclass = new SomeClass();
    }

    public Type GetInterfaceInSomeWay()
    {
        //some code
    }

}

I need to fill the commented area. Thanks in advance for your help, community!

like image 331
Milos Maksimovic Avatar asked Jul 23 '13 10:07

Milos Maksimovic


1 Answers

typeof(SomeClass).GetInterfaces()

like image 178
nothrow Avatar answered Oct 31 '22 12:10

nothrow