2013-07-23 5 views
5

クラスが実装するインタフェースの型を取得する方法はありますか?問題の詳細な説明については、ここで私が何を意味しているのですか。例:クラスが実装するインタフェースのタイプを返すC#

public interface ISomeInterface 
{ 

} 

public class SomeClass : ISomeInterface 
{ 

} 

public class SecondClass 
{ 

    ISomeInterface someclass; 

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

    public Type GetInterfaceInSomeWay() 
    { 
     //some code 
    } 

} 

コメント欄に記入する必要があります。あなたの助け、コミュニティのために事前に感謝!

+1

可能な重複:http://stackoverflow.com/questions/26733/getting-all-types-that-implement-an-interface-with-c-sharp-3-0 – FSou1

+2

@ FSou1私はこの質問は、その質問の正確な反対を尋ねていると思う[反映されたインターフェイスを見つけるために反射を使用して –

+0

の可能な複製](http://stackoverflow.com/questions/1519530/using-reflection-to-find-interfaces-implemented ) – nothrow

答えて

8

typeof(SomeClass).GetInterfaces()

0
foreach (Type tinterface in typeof(SomeClass).GetInterfaces()) 
{ 
    Console.WriteLine(tinterface.ToString()); 
} 
関連する問題