MemberTypes 枚举
标记每个已定义为 MemberInfo 的派生类的成员类型。
此枚举有一个 FlagsAttribute 属性,允许其成员值按位组合。
**命名空间:**System.Reflection
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
<SerializableAttribute> _
<FlagsAttribute> _
<ComVisibleAttribute(True)> _
Public Enumeration MemberTypes
用法
Dim instance As MemberTypes
[SerializableAttribute]
[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum MemberTypes
[SerializableAttribute]
[FlagsAttribute]
[ComVisibleAttribute(true)]
public enum class MemberTypes
/** @attribute SerializableAttribute() */
/** @attribute FlagsAttribute() */
/** @attribute ComVisibleAttribute(true) */
public enum MemberTypes
SerializableAttribute
FlagsAttribute
ComVisibleAttribute(true)
public enum MemberTypes
成员
成员名称 | 说明 | |
---|---|---|
All | 指定所有成员类型。 | |
Constructor | 指定该成员是一个构造函数,表示 ConstructorInfo 成员。0x01 的十六进制值。 | |
Custom | 指定该成员是一个自定义成员类型。0x40 的十六进制值。 | |
Event | 指定该成员是一个事件,表示 EventInfo 成员。0x02 的十六进制值。 | |
Field | 指定该成员是一个字段,表示 FieldInfo 成员。0x04 的十六进制值。 | |
Method | 指定该成员是一个方法,表示 MethodInfo 成员。0x08 的十六进制值。 | |
NestedType | 指定该成员是一个嵌套类型,可扩展 MemberInfo。 | |
Property | 指定该成员是一个属性,表示 PropertyInfo 成员。0x10 的十六进制值。 | |
TypeInfo | 指定该成员是一种类型,表示 TypeInfo 成员。0x20 的十六进制值。 |
备注
这些枚举值由 MemberType 返回并可用于 switch 语句。MemberTypes 与 corhdr.h 文件中定义的 CorTypeAttr 相匹配。
若要获取某一方法的 MemberTypes 值:
先获取 Type。
从 Type 获取 MemberInfo 数组。
从 MemberInfo 数组获取 MemberType。
示例
下面的示例显示指定类的成员类型。
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Class membertypesenum
Public Overloads Shared Function Main(ByVal args() As String) As Integer
Console.WriteLine(ControlChars.Lf & "Reflection.MemberTypes")
Dim Mymembertypes As MemberTypes
' Get the type of a chosen class.
Dim Mytype As Type = Type.GetType("System.Reflection.ReflectionTypeLoadException")
' Get the MemberInfo array.
Dim Mymembersinfoarray As MemberInfo() = Mytype.GetMembers()
' Get and display the name and the MemberType for each member.
Dim Mymemberinfo As MemberInfo
For Each Mymemberinfo In Mymembersinfoarray
Mymembertypes = Mymemberinfo.MemberType
Console.WriteLine("The member {0} of {1} is a {2}.", Mymemberinfo.Name, Mytype, Mymembertypes.ToString())
Next Mymemberinfo
Return 0
End Function 'Main
End Class 'membertypesenum
using System;
using System.Reflection;
class membertypesenum
{
public static int Main(string[] args)
{
Console.WriteLine ("\nReflection.MemberTypes");
MemberTypes Mymembertypes;
// Get the type of a chosen class.
Type Mytype = Type.GetType
("System.Reflection.ReflectionTypeLoadException");
// Get the MemberInfo array.
MemberInfo[] Mymembersinfoarray = Mytype.GetMembers();
// Get and display the name and the MemberType for each member.
foreach (MemberInfo Mymemberinfo in Mymembersinfoarray)
{
Mymembertypes = Mymemberinfo.MemberType;
Console.WriteLine("The member {0} of {1} is a {2}.", Mymemberinfo.Name, Mytype, Mymembertypes.ToString());
}
return 0;
}
}
using namespace System;
using namespace System::Reflection;
int main()
{
Console::WriteLine( "\nReflection.MemberTypes" );
MemberTypes Mymembertypes;
// Get the type of a chosen class.
Type^ Mytype = Type::GetType( "System.Reflection.ReflectionTypeLoadException" );
// Get the MemberInfo array.
array<MemberInfo^>^Mymembersinfoarray = Mytype->GetMembers();
// Get and display the name and the MemberType for each member.
System::Collections::IEnumerator^ enum0 = Mymembersinfoarray->GetEnumerator();
while ( enum0->MoveNext() )
{
MemberInfo^ Mymemberinfo = safe_cast<MemberInfo^>(enum0->Current);
Mymembertypes = Mymemberinfo->MemberType;
Console::WriteLine( "The member {0} of {1} is a {2}.", Mymemberinfo->Name, Mytype, Mymembertypes );
}
return 0;
}
import System.*;
import System.Reflection.*;
class MemberTypesEnum
{
public static void main(String[] args)
{
Console.WriteLine("\nReflection.MemberTypes");
MemberTypes myMemberTypes;
// Get the type of a chosen class.
Type myType =
Type.GetType("System.Reflection.ReflectionTypeLoadException");
// Get the MemberInfo array.
MemberInfo myMemberInfoArray[] = myType.GetMembers();
// Get and display the name and the MemberType for each member.
for (int iCtr = 0; iCtr < myMemberInfoArray.length ; iCtr++) {
MemberInfo myMemberInfo = myMemberInfoArray[iCtr];
myMemberTypes = myMemberInfo.get_MemberType();
Console.WriteLine("The member {0} of {1} is a {2}.",
myMemberInfo.get_Name(), myType, myMemberTypes.ToString());
}
} //main
} //MemberTypesEnum
平台
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