Type.GetMembers 메서드
정의
오버로드
GetMembers() |
현재 Type의 모든 public 멤버를 반환합니다.Returns all the public members of the current Type. |
GetMembers(BindingFlags) |
파생 클래스에서 재정의되면, 현재 Type에 대해 정의된 멤버를 지정된 바인딩 제약 조건으로 검색합니다.When overridden in a derived class, searches for the members defined for the current Type, using the specified binding constraints. |
GetMembers()
public:
cli::array <System::Reflection::MemberInfo ^> ^ GetMembers();
public:
virtual cli::array <System::Reflection::MemberInfo ^> ^ GetMembers();
public System.Reflection.MemberInfo[] GetMembers ();
member this.GetMembers : unit -> System.Reflection.MemberInfo[]
abstract member GetMembers : unit -> System.Reflection.MemberInfo[]
override this.GetMembers : unit -> System.Reflection.MemberInfo[]
Public Function GetMembers () As MemberInfo()
반환
현재 MemberInfo의 모든 public 멤버를 나타내는 Type 개체의 배열입니다.An array of MemberInfo objects representing all the public members of the current Type.
또는-or- 현재 MemberInfo에 public 멤버가 없을 경우 Type 형식의 빈 배열입니다.An empty array of type MemberInfo, if the current Type does not have public members.
구현
예제
다음 코드 예제에서는 메서드 오버 로드를 사용 하 여 GetMembers() 지정 된 클래스의 모든 공용 멤버에 대 한 정보를 수집 하는 방법을 보여 줍니다.The following code example demonstrates how to use the GetMembers() method overload to collect information about all public members of a specified class.
ref class MyClass
{
public:
int myInt;
String^ myString;
MyClass(){}
void Myfunction(){}
};
int main()
{
try
{
MyClass^ myObject = gcnew MyClass;
array<MemberInfo^>^myMemberInfo;
// Get the type of 'MyClass'.
Type^ myType = myObject->GetType();
// Get the information related to all public members of 'MyClass'.
myMemberInfo = myType->GetMembers();
Console::WriteLine( "\nThe members of class '{0}' are :\n", myType );
for ( int i = 0; i < myMemberInfo->Length; i++ )
{
// Display name and type of the concerned member.
Console::WriteLine( "'{0}' is a {1}", myMemberInfo[ i ]->Name, myMemberInfo[ i ]->MemberType );
}
}
catch ( SecurityException^ e )
{
Console::WriteLine( "Exception : {0}", e->Message );
}
}
class MyClass
{
public int myInt = 0;
public string myString = null;
public MyClass()
{
}
public void Myfunction()
{
}
}
class Type_GetMembers
{
public static void Main()
{
try
{
MyClass myObject = new MyClass();
MemberInfo[] myMemberInfo;
// Get the type of 'MyClass'.
Type myType = myObject.GetType();
// Get the information related to all public member's of 'MyClass'.
myMemberInfo = myType.GetMembers();
Console.WriteLine( "\nThe members of class '{0}' are :\n", myType);
for (int i =0 ; i < myMemberInfo.Length ; i++)
{
// Display name and type of the concerned member.
Console.WriteLine( "'{0}' is a {1}", myMemberInfo[i].Name, myMemberInfo[i].MemberType);
}
}
catch(SecurityException e)
{
Console.WriteLine("Exception : " + e.Message );
}
}
}
Class [MyClass]
Public myInt As Integer = 0
Public myString As String = Nothing
Public Sub New()
End Sub
Public Sub Myfunction()
End Sub
End Class
Class Type_GetMembers
Public Shared Sub Main()
Try
Dim myObject As New [MyClass]()
Dim myMemberInfo() As MemberInfo
' Get the type of 'MyClass'.
Dim myType As Type = myObject.GetType()
' Get the information related to all public member's of 'MyClass'.
myMemberInfo = myType.GetMembers()
Console.WriteLine(ControlChars.Cr + "The members of class '{0}' are :" + ControlChars.Cr, myType)
Dim i As Integer
For i = 0 To myMemberInfo.Length - 1
' Display name and type of the concerned member.
Console.WriteLine("'{0}' is a {1}", myMemberInfo(i).Name, myMemberInfo(i).MemberType)
Next i
Catch e As SecurityException
Console.WriteLine(("Exception : " + e.Message.ToString()))
End Try
End Sub
End Class
설명
멤버에는 속성, 메서드, 생성자, 필드, 이벤트 및 중첩 형식이 포함 됩니다.Members include properties, methods, constructors, fields, events, and nested types.
GetMembers메서드는 사전순 또는 선언 순서와 같은 특정 순서로 멤버를 반환 하지 않습니다.The GetMembers method does not return members in a particular order, such as alphabetical or declaration order. 코드가 반환 되는 순서에 따라 달라 지는 것은 아닙니다.Your code must not depend on the order in which members are returned, because that order varies.
이 메서드 오버 로드는 GetMembers(BindingFlags) BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static ( BindingFlags.Public Or
BindingFlags.Instance Or
BindingFlags.Static Visual Basic)를 사용 하 여 메서드 오버 로드를 호출 합니다.This method overload calls the GetMembers(BindingFlags) method overload, with BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static (BindingFlags.PublicOr
BindingFlags.InstanceOr
BindingFlags.Static in Visual Basic). 클래스 이니셜라이저 (정적 생성자)를 찾을 수 없습니다.It will not find class initializers (static constructors). 클래스 이니셜라이저를 찾으려면 GetMembers(BindingFlags) 오버 로드를 호출 하 고 BindingFlags.Static Visual Basic에서 |를 지정 BindingFlags.NonPublic BindingFlags.Static Or
BindingFlags.NonPublic 합니다.To find class initializers, call the GetMembers(BindingFlags) overload, and specify BindingFlags.Static | BindingFlags.NonPublic (BindingFlags.StaticOr
BindingFlags.NonPublic in Visual Basic). 속성을 사용 하 여 클래스 이니셜라이저를 가져올 수도 있습니다 TypeInitializer .You can also get the class initializer using the TypeInitializer property.
다음 표에서는 Get
형식에 대해 리플렉션할 때 메서드에서 반환 되는 기본 클래스의 멤버를 보여 줍니다.The following table shows what members of a base class are returned by the Get
methods when reflecting on a type.
멤버 형식Member Type | 정적Static | 비정적Non-Static |
---|---|---|
생성자Constructor | 아니요No | 아니요No |
필드Field | 아니요No | 예.Yes. 필드는 항상 이름 및 시그니처로 숨겨집니다.A field is always hide-by-name-and-signature. |
이벤트Event | 해당 없음Not applicable | 공용 형식 시스템 규칙은 상속이 속성을 구현 하는 메서드와 동일 하다는 것입니다.The common type system rule is that the inheritance is the same as that of the methods that implement the property. 리플렉션에서는 속성을 이름으로 숨기기-서명으로 처리 합니다.Reflection treats properties as hide-by-name-and-signature. 아래의 참고 2를 참조 하세요.See note 2 below. |
메서드Method | 아니요No | 예.Yes. 메서드 (가상 및 비가상)는 이름을 기준으로 숨기 거 나 이름에 따라 숨길 수 있습니다.A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature. |
중첩 형식Nested Type | 아니요No | 아니요No |
속성Property | 해당 없음Not applicable | 공용 형식 시스템 규칙은 상속이 속성을 구현 하는 메서드와 동일 하다는 것입니다.The common type system rule is that the inheritance is the same as that of the methods that implement the property. 리플렉션에서는 속성을 이름으로 숨기기-서명으로 처리 합니다.Reflection treats properties as hide-by-name-and-signature. 아래의 참고 2를 참조 하세요.See note 2 below. |
이름 및 시그니처는 사용자 지정 한정자, 반환 형식, 매개 변수 형식, 센티널 및 관리 되지 않는 호출 규칙을 포함 하 여 시그니처의 모든 부분을 고려 합니다.Hide-by-name-and-signature considers all of the parts of the signature, including custom modifiers, return types, parameter types, sentinels, and unmanaged calling conventions. 이는 이진 비교입니다.This is a binary comparison.
리플렉션의 경우 속성과 이벤트는 이름 및 시그니처로 숨겨집니다.For reflection, properties and events are hide-by-name-and-signature. 기본 클래스에 get 및 set 접근자가 모두 포함 된 속성이 있지만 파생 클래스에 get 접근자만 있는 경우 파생 클래스 속성은 기본 클래스 속성을 숨기고 기본 클래스의 setter에 액세스할 수 없게 됩니다.If you have a property with both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and you will not be able to access the setter on the base class.
사용자 지정 특성은 공용 형식 시스템의 일부가 아닙니다.Custom attributes are not part of the common type system.
현재 Type 이 생성 된 제네릭 형식을 나타내는 경우이 메서드는 MemberInfo 형식 매개 변수를 적절 한 형식 인수로 대체 하 여 개체를 반환 합니다.If the current Type represents a constructed generic type, this method returns the MemberInfo objects with the type parameters replaced by the appropriate type arguments.
현재 Type 이 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우이 메서드는 클래스 제약 조건의 멤버나 Object 클래스 제약 조건이 없는 경우의 멤버를 검색 합니다.If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the members of the class constraint, or the members of Object if there is no class constraint.
추가 정보
- MemberInfo
- GetMember(String)
- GetDefaultMembers()
- FindMembers(MemberTypes, BindingFlags, MemberFilter, Object)
적용 대상
GetMembers(BindingFlags)
public:
abstract cli::array <System::Reflection::MemberInfo ^> ^ GetMembers(System::Reflection::BindingFlags bindingAttr);
public abstract System.Reflection.MemberInfo[] GetMembers (System.Reflection.BindingFlags bindingAttr);
abstract member GetMembers : System.Reflection.BindingFlags -> System.Reflection.MemberInfo[]
Public MustOverride Function GetMembers (bindingAttr As BindingFlags) As MemberInfo()
매개 변수
- bindingAttr
- BindingFlags
검색 방법을 지정하는 열거형 값의 비트 조합입니다.A bitwise combination of the enumeration values that specify how the search is conducted.
또는-or- 빈 배열을 반환하는 Default입니다.Default to return an empty array.
반환
현재 MemberInfo에 대해 정의된 필드 중 지정된 바인딩 제약 조건과 일치하는 모든 멤버를 나타내는 Type 개체의 배열입니다.An array of MemberInfo objects representing all members defined for the current Type that match the specified binding constraints.
또는-or- 현재 Type에 대해 정의된 멤버가 없거나 정의된 멤버 중 바인딩 제약 조건과 일치하는 멤버가 없을 경우 빈 배열입니다.An empty array if no members are defined for the current Type, or if none of the defined members match the binding constraints.
구현
예제
다음 코드 예제에서는 메서드 오버 로드를 사용 하 여 GetMembers(BindingFlags) 지정 된 클래스의 모든 public 인스턴스 멤버에 대 한 정보를 수집 하는 방법을 보여 줍니다.The following code example demonstrates how to use the GetMembers(BindingFlags) method overload to collect information about all public instance members of a specified class.
ref class MyClass
{
public:
int * myInt;
String^ myString;
MyClass(){}
void Myfunction(){}
};
int main()
{
try
{
MyClass^ MyObject = gcnew MyClass;
array<MemberInfo^>^myMemberInfo;
// Get the type of the class 'MyClass'.
Type^ myType = MyObject->GetType();
// Get the public instance members of the class 'MyClass'.
myMemberInfo = myType->GetMembers( static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Instance) );
Console::WriteLine( "\nThe public instance members of class '{0}' are : \n", myType );
for ( int i = 0; i < myMemberInfo->Length; i++ )
{
// Display name and type of the member of 'MyClass'.
Console::WriteLine( "'{0}' is a {1}", myMemberInfo[ i ]->Name, myMemberInfo[ i ]->MemberType );
}
}
catch ( SecurityException^ e )
{
Console::WriteLine( "SecurityException : {0}", e->Message );
}
//Output:
//The public instance members of class 'MyClass' are :
//'Myfunction' is a Method
//'ToString' is a Method
//'Equals' is a Method
//'GetHashCode' is a Method
//'GetType' is a Method
//'.ctor' is a Constructor
//'myInt' is a Field
//'myString' is a Field
}
class MyClass
{
public int myInt = 0;
public string myString = null;
public MyClass()
{
}
public void Myfunction()
{
}
}
class Type_GetMembers_BindingFlags
{
public static void Main()
{
try
{
MyClass MyObject = new MyClass();
MemberInfo [] myMemberInfo;
// Get the type of the class 'MyClass'.
Type myType = MyObject.GetType();
// Get the public instance members of the class 'MyClass'.
myMemberInfo = myType.GetMembers(BindingFlags.Public|BindingFlags.Instance);
Console.WriteLine( "\nThe public instance members of class '{0}' are : \n", myType);
for (int i =0 ; i < myMemberInfo.Length ; i++)
{
// Display name and type of the member of 'MyClass'.
Console.WriteLine( "'{0}' is a {1}", myMemberInfo[i].Name, myMemberInfo[i].MemberType);
}
}
catch (SecurityException e)
{
Console.WriteLine("SecurityException : " + e.Message );
}
//Output:
//The public instance members of class 'MyClass' are :
//'Myfunction' is a Method
//'ToString' is a Method
//'Equals' is a Method
//'GetHashCode' is a Method
//'GetType' is a Method
//'.ctor' is a Constructor
//'myInt' is a Field
//'myString' is a Field
}
}
Class [MyClass]
Public myInt As Integer = 0
Public myString As String = Nothing
Public Sub New()
End Sub
Public Sub Myfunction()
End Sub
End Class
Class Type_GetMembers_BindingFlags
Public Shared Sub Main()
Try
Dim MyObject As New [MyClass]()
Dim myMemberInfo() As MemberInfo
' Get the type of the class 'MyClass'.
Dim myType As Type = MyObject.GetType()
' Get the public instance members of the class 'MyClass'.
myMemberInfo = myType.GetMembers((BindingFlags.Public Or BindingFlags.Instance))
Console.WriteLine(ControlChars.Cr + "The public instance members of class '{0}' are : " + ControlChars.Cr, myType)
Dim i As Integer
For i = 0 To myMemberInfo.Length - 1
' Display name and type of the member of 'MyClass'.
Console.WriteLine("'{0}' is a {1}", myMemberInfo(i).Name, myMemberInfo(i).MemberType)
Next i
Catch e As SecurityException
Console.WriteLine(("SecurityException : " + e.Message.ToString()))
End Try
'Output:
'The public instance members of class 'MyClass' are :
''Myfunction' is a Method
''ToString' is a Method
''Equals' is a Method
''GetHashCode' is a Method
''GetType' is a Method
''.ctor' is a Constructor
''myInt' is a Field
''myString' is a Field
End Sub
End Class
설명
멤버에는 속성, 메서드, 생성자, 필드, 이벤트 및 중첩 형식이 포함 됩니다.Members include properties, methods, constructors, fields, events, and nested types.
GetMethods(BindingFlags)
오버 로드에서 메서드 정보를 성공적으로 검색 하려면 인수에 및 중 적어도 bindingAttr
하나 이상이 포함 되어야 합니다 BindingFlags.Instance BindingFlags.Static BindingFlags.NonPublic BindingFlags.Public .For the GetMethods(BindingFlags)
overload to successfully retrieve method information, the bindingAttr
argument must include at least one of BindingFlags.Instance and BindingFlags.Static, along with at least one of BindingFlags.NonPublic and BindingFlags.Public. 유일한 예외는 BindingFlags.NonPublic 중첩 된 형식에 대 한 멤버 정보를 반환 하는에 대 한 메서드 호출입니다.The sole exception is a method call with BindingFlags.NonPublic, which returns member information about nested types.
다음 BindingFlags 필터 플래그는 검색에 포함할 멤버를 정의 하는 데 사용할 수 있습니다.The following BindingFlags filter flags can be used to define which members to include in the search:
BindingFlags.Instance
인스턴스 메서드를 포함 하도록 지정 합니다.SpecifyBindingFlags.Instance
to include instance methods.BindingFlags.Static
정적 메서드를 포함 하도록 지정 합니다.SpecifyBindingFlags.Static
to include static methods.BindingFlags.Public
검색에 공용 메서드를 포함 하도록 지정 합니다.SpecifyBindingFlags.Public
to include public methods in the search.BindingFlags.NonPublic
검색에 public이 아닌 메서드 (private, internal 및 protected 메서드)를 포함 하도록 지정 합니다.SpecifyBindingFlags.NonPublic
to include non-public methods (that is, private, internal, and protected methods) in the search. 기본 클래스의 보호 된 메서드와 내부 메서드만 반환 됩니다. 기본 클래스의 전용 메서드는 반환 되지 않습니다.Only protected and internal methods on base classes are returned; private methods on base classes are not returned.BindingFlags.FlattenHierarchy
public
계층의 정적 멤버를 포함 하도록 지정 합니다. 상속 된protected
private
클래스의 정적 멤버는 포함 되지 않습니다.SpecifyBindingFlags.FlattenHierarchy
to includepublic
andprotected
static members up the hierarchy;private
static members in inherited classes are not included.BindingFlags.Default
빈 배열을 반환 하려면만 지정 MethodInfo 합니다.SpecifyBindingFlags.Default
alone to return an empty MethodInfo array.
다음 BindingFlags 한정자 플래그를 사용 하 여 검색의 작동 방식을 변경할 수 있습니다.The following BindingFlags modifier flags can be used to change how the search works:
BindingFlags.DeclaredOnly
단순히 상속 된 멤버가 아니라에 선언 된 멤버만 검색 합니다 Type .BindingFlags.DeclaredOnly
to search only the members declared on the Type, not members that were simply inherited.
자세한 내용은 System.Reflection.BindingFlags를 참조하세요.See System.Reflection.BindingFlags for more information.
GetMembers메서드는 사전순 또는 선언 순서와 같은 특정 순서로 멤버를 반환 하지 않습니다.The GetMembers method does not return members in a particular order, such as alphabetical or declaration order. 코드가 반환 되는 순서에 따라 달라 지는 것은 아닙니다.Your code must not depend on the order in which members are returned, because that order varies.
이 메서드 오버 로드를 사용 하 여 클래스 이니셜라이저 (정적 생성자)를 가져오려면 BindingFlags.Static | BindingFlags.NonPublic ( BindingFlags.Static Or
BindingFlags.NonPublic Visual Basic)를 지정 해야 합니다.To get the class initializer (static constructor) using this method overload, you must specify BindingFlags.Static | BindingFlags.NonPublic (BindingFlags.StaticOr
BindingFlags.NonPublic in Visual Basic). 속성을 사용 하 여 클래스 이니셜라이저를 가져올 수도 있습니다 TypeInitializer .You can also get the class initializer using the TypeInitializer property.
현재 Type 이 생성 된 제네릭 형식을 나타내는 경우이 메서드는 MemberInfo 형식 매개 변수를 적절 한 형식 인수로 대체 하 여 개체를 반환 합니다.If the current Type represents a constructed generic type, this method returns the MemberInfo objects with the type parameters replaced by the appropriate type arguments.
현재 Type 이 제네릭 형식 또는 제네릭 메서드 정의의 형식 매개 변수를 나타내는 경우이 메서드는 클래스 제약 조건의 멤버나 Object 클래스 제약 조건이 없는 경우의 멤버를 검색 합니다.If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the members of the class constraint, or the members of Object if there is no class constraint.
추가 정보
- MemberInfo
- BindingFlags
- DefaultBinder
- GetMember(String)
- GetDefaultMembers()
- FindMembers(MemberTypes, BindingFlags, MemberFilter, Object)