Type.GetInterfaces 方法
当在派生类中重写时,获取由当前 Type 实现或继承的所有接口。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public MustOverride Function GetInterfaces As Type()
用法
Dim instance As Type
Dim returnValue As Type()
returnValue = instance.GetInterfaces
public abstract Type[] GetInterfaces ()
public:
virtual array<Type^>^ GetInterfaces () abstract
public abstract Type[] GetInterfaces ()
public abstract function GetInterfaces () : Type[]
返回值
表示由当前 Type 实现或继承的所有接口的 Type 对象数组。 - 或 - 如果没有由当前 Type 实现或继承的接口,则为 Type 类型的空数组。
异常
异常类型 | 条件 |
---|---|
调用静态初始值设定项并引发异常。 |
备注
如果当前 Type 表示构造泛型类型,则此方法将返回 Type 对象,并且其类型形参替换为相应的类型实参。
如果当前 Type 表示泛型类型或泛型方法的定义中的类型参数,则此方法搜索接口约束以及从类或接口约束继承的所有接口。
示例
下面的示例获取指定类的类型,并显示该类型实现或继承的所有接口。若要编译 Visual Basic 示例,请使用以下编译器命令:
vbc type_getinterfaces1.vb /r:System.Web.dll /r:System.dll
Imports System
Imports System.Web
Imports System.Web.UI
Imports Microsoft.VisualBasic
Namespace Samples
Public Class MyTemplate
Inherits Control
Implements INamingContainer
Private _message As [String] = Nothing
Public Property Message() As [String]
Get
Return _message
End Get
Set(ByVal Value As [String])
_message = value
End Set
End Property
End Class
Public Class MyInterfacesSample
Public Shared Sub Main()
Try
Dim myObjectArray As Type() = GetType(MyTemplate).GetInterfaces()
Console.WriteLine("The interfaces inherited by the MyTemplate class are:" + ControlChars.CrLf)
Dim index As Integer
For index = 0 To myObjectArray.Length - 1
Console.WriteLine(myObjectArray(index))
Next index
Catch e As Exception
Console.WriteLine("An exception occurred.")
Console.WriteLine("Message: {0}", e.Message)
End Try
End Sub
End Class
End Namespace
using System;
using System.Web;
using System.Web.UI;
namespace Samples
{
public class MyTemplate : Control, INamingContainer
{
private String _message = null;
public String Message
{
get
{
return _message;
}
set
{
_message = value;
}
}
}
public class MyInterfacesSample
{
public static void Main()
{
try
{
Type[] myObjectArray= typeof(MyTemplate).GetInterfaces();
Console.WriteLine("The interfaces inherited by the MyTemplate class are:\n");
for (int index = 0; index < myObjectArray.Length; index++)
{
Console.WriteLine(myObjectArray[index]);
}
}
catch (Exception e)
{
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message: " + e.Message);
}
}
}
}
#using <system.dll>
#using <system.web.dll>
using namespace System;
using namespace System::Web;
using namespace System::Web::UI;
public ref class MyTemplate: public Control, public INamingContainer
{
private:
String^ _message;
public:
property String^ Message
{
String^ get()
{
return _message;
}
void set( String^ value )
{
_message = value;
}
}
};
int main()
{
try
{
array<Type^>^myObjectArray = MyTemplate::typeid->GetInterfaces();
Console::WriteLine( "The interfaces inherited by the MyTemplate class are:\n" );
for ( int index = 0; index < myObjectArray->Length; index++ )
{
Console::WriteLine( myObjectArray[ index ] );
}
}
catch ( Exception^ e )
{
Console::WriteLine( "An exception occurred." );
Console::WriteLine( "Message: {0}", e->Message );
}
}
package Samples;
import System.*;
import System.Web.*;
import System.Web.UI.*;
public class MyTemplate extends Control implements INamingContainer
{
private String _message = null;
/** @property
*/
public String get_Message()
{
return _message;
} //get_Message
/** @property
*/
public void set_Message(String value)
{
_message = value;
} //set_Message
} //MyTemplate
public class MyInterfacesSample
{
public static void main(String[] args)
{
try {
Type myObjectArray[] = MyTemplate.class.ToType().GetInterfaces();
Console.WriteLine("The interfaces inherited by the MyTemplate"
+ " class are:\n");
for (int index = 0; index < myObjectArray.length; index++) {
Console.WriteLine(myObjectArray.get_Item(index));
}
}
catch (System.Exception e) {
Console.WriteLine("An exception occurred.");
Console.WriteLine("Message: " + e.get_Message());
}
} //main
} //MyInterfacesSample
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0