MemberInfo.MemberType 属性
在派生类中被重写时,获取一个 MemberTypes 值,指示此成员的类型(方法、构造函数和事件等)。
**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public MustOverride ReadOnly Property MemberType As MemberTypes
用法
Dim instance As MemberInfo
Dim value As MemberTypes
value = instance.MemberType
public abstract MemberTypes MemberType { get; }
public:
virtual property MemberTypes MemberType {
MemberTypes get () abstract;
}
/** @property */
public abstract MemberTypes get_MemberType ()
public abstract function get MemberType () : MemberTypes
属性值
指示成员类型的 MemberTypes 值。
备注
此属性在派生类中被重写,并且此重写返回相应的成员类型。因此,检查一组 MemberInfo 对象(例如,GetMembers 返回的数组)时,MemberType 属性可以用于确定任意给定成员的成员类型。
若要获取 MemberType 属性,请获取 Type 类。从 Type 获取 MethodInfo 数组。从 MethodInfo 数组获取 MemberTypes。
示例
下面的示例显示指定类的成员名及类型。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Class Mymemberinfo
Public Shared Function Main() As Integer
Console.WriteLine(ControlChars.Cr + "Reflection.MemberInfo")
' Get the Type and MemberInfo.
Dim MyType As Type = Type.GetType("System.Reflection.PropertyInfo")
Dim Mymemberinfoarray As MemberInfo() = MyType.GetMembers()
' Get the MemberType method and display the elements.
Console.Write(ControlChars.Cr + "There are {0} members in ", _
Mymemberinfoarray.GetLength(0))
Console.Write("{0}.", MyType.FullName)
Dim counter As Integer
For counter = 0 To Mymemberinfoarray.Length - 1
Console.Write(ControlChars.CrLf + counter.ToString() + ". " _
+ Mymemberinfoarray(counter).Name _
+ " Member type - " _
+ Mymemberinfoarray(counter).MemberType.ToString())
Next counter
Return 0
End Function
End Class
using System;
using System.Reflection;
class Mymemberinfo
{
public static int Main()
{
Console.WriteLine ("\nReflection.MemberInfo");
// Get the Type and MemberInfo.
Type MyType = Type.GetType("System.Reflection.PropertyInfo");
MemberInfo[] Mymemberinfoarray = MyType.GetMembers();
// Get the MemberType method and display the elements.
Console.Write("\nThere are {0} members in ", Mymemberinfoarray.GetLength(0));
Console.Write("{0}.", MyType.FullName);
for (int counter = 0; counter < Mymemberinfoarray.Length; counter++)
{
Console.Write("\n" + counter + ". "
+ Mymemberinfoarray[counter].Name
+ " Member type - " +
Mymemberinfoarray[counter].MemberType.ToString());
}
return 0;
}
}
using namespace System;
using namespace System::Reflection;
int main()
{
Console::WriteLine( "\nReflection.MemberInfo" );
// Get the Type and MemberInfo.
Type^ MyType = Type::GetType( "System.Reflection.PropertyInfo" );
array<MemberInfo^>^Mymemberinfoarray = MyType->GetMembers();
// Get the MemberType method and display the elements.
Console::Write( "\nThere are {0} members in ", Mymemberinfoarray->GetLength( 0 ) );
Console::Write( "{0}.", MyType->FullName );
for ( int counter = 0; counter < Mymemberinfoarray->Length; counter++ )
{
Console::Write( "\n{0}. {1} Member type - {2}", counter, Mymemberinfoarray[ counter ]->Name, Mymemberinfoarray[ counter ]->MemberType );
}
return 0;
}
import System.*;
import System.Reflection.*;
class MyMemberInfo
{
public static void main(String[] args)
{
Console.WriteLine("\nReflection.MemberInfo");
// Get the Type and MemberInfo.
Type myType = Type.GetType("System.Reflection.PropertyInfo");
MemberInfo myMemberInfoArray[] = myType.GetMembers();
// Get the MemberType method and display the elements.
Console.Write("\nThere are {0} members in ",
String.valueOf(myMemberInfoArray.GetLength(0)));
Console.Write("{0}.", myType.get_FullName());
for (int counter=0; counter < myMemberInfoArray.length; counter++) {
Console.Write(("\n" + counter + ". "
+ myMemberInfoArray[counter].get_Name() + " Member type - "
+ myMemberInfoArray[counter].get_MemberType().toString()));
}
} //main
} //MyMemberInfo
import System;
import System.Reflection;
class Mymemberinfo
{
public static function Main() : void
{
Console.WriteLine ("\nReflection.MemberInfo");
//Get the Type and MemberInfo.
var MyType : Type = Type.GetType("System.Reflection.PropertyInfo");
var Mymemberinfoarray : MemberInfo[] = MyType.GetMembers();
//Get the MemberType method and display the elements.
Console.Write("\nThere are {0} members in ",
Mymemberinfoarray.GetLength(0));
Console.Write("{0}.", MyType.FullName);
for (var counter : int in Mymemberinfoarray)
{
Console.Write("\n" + counter + ". "
+ Mymemberinfoarray[counter].Name
+ " Member type - " +
Mymemberinfoarray[counter].MemberType.ToString());
}
}
}
Mymemberinfo.Main();
平台
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
请参见
参考
MemberInfo 类
MemberInfo 成员
System.Reflection 命名空间
MemberTypes