MemberInfo.MemberType 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在衍生類別中覆寫時,取得 MemberTypes 值,指出成員類型︰方法、建構函式、事件等。
public:
abstract property System::Reflection::MemberTypes MemberType { System::Reflection::MemberTypes get(); };
public abstract System.Reflection.MemberTypes MemberType { get; }
member this.MemberType : System.Reflection.MemberTypes
Public MustOverride ReadOnly Property MemberType As MemberTypes
屬性值
MemberTypes 值,表示成員類型。
實作
範例
下列範例會顯示指定類別的成員名稱和類型。
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;
}
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;
}
}
Imports System.Reflection
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
備註
這個屬性會在衍生類別中覆寫,而覆寫會傳回適當的成員類型。 因此,當您檢查一組MemberInfo物件時,例如,傳GetMembersMemberType回的陣列可用來判斷任何指定成員的成員類型。
若要取得 MemberType
屬性,請取得 類別 Type。
Type
從取得MethodInfo陣列。 從陣列取得 MethodInfo
MemberTypes
。