MemberTypes 枚举
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
标记被定义为 MemberInfo 的派生类的每种成员类型。
此枚举支持其成员值的按位组合。
public enum class MemberTypes
[System.Flags]
public enum MemberTypes
[System.Flags]
[System.Serializable]
public enum MemberTypes
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum MemberTypes
[<System.Flags>]
type MemberTypes =
[<System.Flags>]
[<System.Serializable>]
type MemberTypes =
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type MemberTypes =
Public Enum MemberTypes
- 继承
- 属性
字段
All | 191 | 指定所有成员类型。 |
Constructor | 1 | 指定该成员是构造函数。 |
Custom | 64 | 指定该成员是自定义成员类型。 |
Event | 2 | 指定该成员是事件。 |
Field | 4 | 指定该成员是字段。 |
Method | 8 | 指定该成员是方法。 |
NestedType | 128 | 指定该成员是嵌套类型。 |
Property | 16 | 指定该成员是属性。 |
TypeInfo | 32 | 指定该成员是类型。 |
示例
以下示例显示 类的成员 ReflectionTypeLoadException 的名称及其关联的成员类型。
using namespace System;
using namespace System::Reflection;
void main()
{
// Get the type of a chosen class.
Type^ t = ReflectionTypeLoadException::typeid;
// Get the MemberInfo array.
array<MemberInfo^>^ members = t->GetMembers();
// Get and display the name and the MemberType for each member.
Console::WriteLine("Members of {0}", t->Name);
for each (MemberInfo^ member in members) {
MemberTypes memberType = member->MemberType;
Console::WriteLine(" {0}: {1}", member->Name, memberType);
}
}
// The example displays the following output:
// Members of ReflectionTypeLoadException
// get_Types: Method
// get_LoaderExceptions: Method
// GetObjectData: Method
// get_Message: Method
// get_Data: Method
// GetBaseException: Method
// get_InnerException: Method
// get_TargetSite: Method
// get_StackTrace: Method
// get_HelpLink: Method
// set_HelpLink: Method
// get_Source: Method
// set_Source: Method
// ToString: Method
// get_HResult: Method
// GetType: Method
// Equals: Method
// GetHashCode: Method
// GetType: Method
// .ctor: Constructor
// .ctor: Constructor
// Types: Property
// LoaderExceptions: Property
// Message: Property
// Data: Property
// InnerException: Property
// TargetSite: Property
// StackTrace: Property
// HelpLink: Property
// Source: Property
// HResult: Property
using System;
using System.Reflection;
class Example
{
public static void Main()
{
// Get the type of a chosen class.
Type t = typeof(ReflectionTypeLoadException);
// Get the MemberInfo array.
MemberInfo[] members = t.GetMembers();
// Get and display the name and the MemberType for each member.
Console.WriteLine("Members of {0}", t.Name);
foreach (var member in members) {
MemberTypes memberType = member.MemberType;
Console.WriteLine(" {0}: {1}", member.Name, memberType);
}
}
}
// The example displays the following output:
// Members of ReflectionTypeLoadException
// get_Types: Method
// get_LoaderExceptions: Method
// GetObjectData: Method
// get_Message: Method
// get_Data: Method
// GetBaseException: Method
// get_InnerException: Method
// get_TargetSite: Method
// get_StackTrace: Method
// get_HelpLink: Method
// set_HelpLink: Method
// get_Source: Method
// set_Source: Method
// ToString: Method
// get_HResult: Method
// GetType: Method
// Equals: Method
// GetHashCode: Method
// GetType: Method
// .ctor: Constructor
// .ctor: Constructor
// Types: Property
// LoaderExceptions: Property
// Message: Property
// Data: Property
// InnerException: Property
// TargetSite: Property
// StackTrace: Property
// HelpLink: Property
// Source: Property
// HResult: Property
Imports System.Reflection
Module Example
Public Sub Main()
' Get the type of a particular class.
Dim t As Type = GetType(ReflectionTypeLoadException)
' Get the MemberInfo array.
Dim members As MemberInfo() = t.GetMembers()
' Get and display the name and the MemberType for each member.
Console.WriteLine("Members of {0}", t.Name)
For Each member In members
Dim memberType As MemberTypes = member.MemberType
Console.WriteLine(" {0}: {1}", member.Name, memberType)
Next
End Sub
End Module
' The example displays the following output:
' Members of ReflectionTypeLoadException
' get_Types: Method
' get_LoaderExceptions: Method
' GetObjectData: Method
' get_Message: Method
' get_Data: Method
' GetBaseException: Method
' get_InnerException: Method
' get_TargetSite: Method
' get_StackTrace: Method
' get_HelpLink: Method
' set_HelpLink: Method
' get_Source: Method
' set_Source: Method
' ToString: Method
' get_HResult: Method
' GetType: Method
' Equals: Method
' GetHashCode: Method
' GetType: Method
' .ctor: Constructor
' .ctor: Constructor
' Types: Property
' LoaderExceptions: Property
' Message: Property
' Data: Property
' InnerException: Property
' TargetSite: Property
' StackTrace: Property
' HelpLink: Property
' Source: Property
' HResult: Property
注解
这些枚举值由以下属性返回:
若要获取 MemberTypes 类型的值,请执行以下命令:
Type获取表示该类型的 对象。
检索 属性的值 Type.MemberType 。
若要获取 MemberTypes 类型的成员的值::
Type获取表示该类型的 对象。
MemberInfo通过调用 方法检索表示该类型的成员的Type.GetMembers数组。
检索数组中每个成员的 From MemberInfo.MemberType 属性的值。
switch
C# 中的语句或Select Case
Visual Basic 中的 语句通常用于处理成员类型。
MemberTypes 匹配 corhdr.h 文件中定义的 CorTypeAttr。