Type.GetProperty 메서드

정의

현재 Type.의 특정 속성을 가져옵니다.

오버로드

Name Description
GetProperty(String, Type, Type[])

매개 변수가 지정된 인수 형식과 일치하는 지정된 public 속성을 검색합니다.

GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

지정된 바인딩 제약 조건을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 속성을 검색합니다.

GetProperty(String, Type, Type[], ParameterModifier[])

매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 public 속성을 검색합니다.

GetProperty(String, Type[])

매개 변수가 지정된 인수 형식과 일치하는 지정된 public 속성을 검색합니다.

GetProperty(String, Type)

지정된 이름과 반환 형식을 사용하여 public 속성을 검색합니다.

GetProperty(String, BindingFlags)

지정된 바인딩 제약 조건을 사용하여 지정된 속성을 검색합니다.

GetProperty(String)

지정된 이름의 public 속성을 검색합니다.

GetProperty(String, Type, Type[])

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

매개 변수가 지정된 인수 형식과 일치하는 지정된 public 속성을 검색합니다.

public:
 System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ types);
public:
 virtual System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ types);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
public System.Reflection.PropertyInfo? GetProperty(string name, Type? returnType, Type[] types);
public System.Reflection.PropertyInfo GetProperty(string name, Type returnType, Type[] types);
public System.Reflection.PropertyInfo? GetProperty(string name, Type? returnType, Type[] types);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)>]
member this.GetProperty : string * Type * Type[] -> System.Reflection.PropertyInfo
member this.GetProperty : string * Type * Type[] -> System.Reflection.PropertyInfo
abstract member GetProperty : string * Type * Type[] -> System.Reflection.PropertyInfo
override this.GetProperty : string * Type * Type[] -> System.Reflection.PropertyInfo
Public Function GetProperty (name As String, returnType As Type, types As Type()) As PropertyInfo

매개 변수

name
String

가져올 public 속성의 이름을 포함하는 문자열입니다.

returnType
Type

속성의 반환 형식입니다.

types
Type[]

가져올 인덱싱된 속성에 Type 대한 매개 변수의 수, 순서 및 형식을 나타내는 개체의 배열입니다.

-또는-

인덱싱되지 않은 속성을 가져오는 형식 Type 의 빈 배열(즉, Type[] types = new Type[0])입니다.

반품

매개 변수가 지정된 인수 형식과 일치하는 public 속성을 나타내는 개체입니다(있는 경우). 그렇지 않으면 . null

구현

특성

예외

지정된 이름과 지정된 인수 형식과 일치하는 속성이 두 개 이상 있습니다.

namenull입니다.

-또는-

typesnull입니다.

types 가 다차원입니다.

types 요소는 .입니다 null.

설명

속성은 공용 접근자가 하나 이상 있으면 리플렉션에서 공용으로 간주됩니다. 그렇지 않으면 속성이 프라이빗으로 간주되며, 속성을 얻으려면 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static를 사용해야 합니다 (Visual Basic에서는 Or를 사용하여 값을 결합합니다).

검색에서 name은 대/소문자를 구분합니다. 검색에는 공용 정적 및 공용 인스턴스 속성이 포함됩니다.

현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 메서드는 적절한 형식 인수로 대체된 형식 매개 변수를 반환 PropertyInfo 합니다.

현재 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 메서드는 클래스 제약 조건의 속성을 검색합니다.

추가 정보

적용 대상

GetProperty(String, BindingFlags, Binder, Type, Type[], ParameterModifier[])

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

지정된 바인딩 제약 조건을 사용하여 매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 속성을 검색합니다.

public:
 virtual System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, Type ^ returnType, cli::array <Type ^> ^ types, cli::array <System::Reflection::ParameterModifier> ^ modifiers);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicProperties | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
public System.Reflection.PropertyInfo? GetProperty(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, Type? returnType, Type[] types, System.Reflection.ParameterModifier[]? modifiers);
public System.Reflection.PropertyInfo GetProperty(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, Type returnType, Type[] types, System.Reflection.ParameterModifier[] modifiers);
public System.Reflection.PropertyInfo? GetProperty(string name, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, Type? returnType, Type[] types, System.Reflection.ParameterModifier[]? modifiers);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicProperties | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)>]
abstract member GetProperty : string * System.Reflection.BindingFlags * System.Reflection.Binder * Type * Type[] * System.Reflection.ParameterModifier[] -> System.Reflection.PropertyInfo
override this.GetProperty : string * System.Reflection.BindingFlags * System.Reflection.Binder * Type * Type[] * System.Reflection.ParameterModifier[] -> System.Reflection.PropertyInfo
abstract member GetProperty : string * System.Reflection.BindingFlags * System.Reflection.Binder * Type * Type[] * System.Reflection.ParameterModifier[] -> System.Reflection.PropertyInfo
override this.GetProperty : string * System.Reflection.BindingFlags * System.Reflection.Binder * Type * Type[] * System.Reflection.ParameterModifier[] -> System.Reflection.PropertyInfo
Public Function GetProperty (name As String, bindingAttr As BindingFlags, binder As Binder, returnType As Type, types As Type(), modifiers As ParameterModifier()) As PropertyInfo

매개 변수

name
String

가져올 속성의 이름을 포함하는 문자열입니다.

bindingAttr
BindingFlags

검색을 수행하는 방법을 지정하는 열거형 값의 비트 조합입니다.

-또는-

Default 를 반환 null합니다.

binder
Binder

속성 집합을 정의하고 바인딩을 사용하도록 설정하는 개체로, 오버로드된 메서드 선택, 인수 형식 강제 변환 및 리플렉션을 통해 멤버 호출을 포함할 수 있습니다.

-또는-

Nothing 사용하는 null 참조(Visual Basic DefaultBinder)입니다.

returnType
Type

속성의 반환 형식입니다.

types
Type[]

가져올 인덱싱된 속성에 Type 대한 매개 변수의 수, 순서 및 형식을 나타내는 개체의 배열입니다.

-또는-

인덱싱되지 않은 속성을 가져오는 형식 Type 의 빈 배열(즉, Type[] types = new Type[0])입니다.

modifiers
ParameterModifier[]

배열의 ParameterModifier 해당 요소와 연결된 특성을 나타내는 개체의 types 배열입니다. 기본 바인더는 이 매개 변수를 처리하지 않습니다.

반품

지정된 요구 사항과 일치하는 속성을 나타내는 개체입니다(있는 경우). 그렇지 않으면 . null

구현

특성

예외

지정된 이름과 지정된 바인딩 제약 조건과 일치하는 두 개 이상의 속성이 있습니다.

namenull입니다.

-또는-

typesnull입니다.

types 가 다차원입니다.

-또는-

modifiers 가 다차원입니다.

-또는-

types 길이 modifiers 가 같지 않습니다.

types 요소는 .입니다 null.

설명

다음 지침은 모든 오버로드에 적용됩니다.

  • 속성은 공용 접근자가 하나 이상 있으면 리플렉션에서 공용으로 간주됩니다. 그렇지 않으면 속성이 프라이빗으로 간주되며, 속성을 얻으려면 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static를 사용해야 합니다 (Visual Basic에서는 Or를 사용하여 값을 결합합니다).
  • 현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 메서드는 적절한 형식 인수로 대체된 형식 매개 변수를 반환 PropertyInfo 합니다.
  • 현재 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 메서드는 클래스 제약 조건의 속성을 검색합니다.

GetProperty(String) 메서드

검색에서 name은 대/소문자를 구분합니다. 검색에는 공용 정적 및 공용 인스턴스 속성이 포함됩니다.

발생하는 상황에는 AmbiguousMatchException 다음이 포함됩니다.

  • 형식에는 이름이 같지만 매개 변수 수가 다른 두 개의 인덱싱된 속성이 포함됩니다. 모호성을 해결하려면 매개 변수 형식을 지정하는 메서드의 GetProperty 오버로드를 사용합니다.
  • 파생 형식은 new 한정자를 사용하여 동일한 이름의 상속된 속성을 가리는 속성을 선언하며, 이는 Visual Basic에서 Shadows 한정자를 사용합니다. 모호성을 해결하려면 메서드 오버로드를 GetProperty(String, BindingFlags) 사용하고 플래그를 BindingFlags.DeclaredOnly 추가하여 상속되지 않은 멤버로 검색을 제한합니다.

GetProperty(String, BindingFlags) 메서드

다음 BindingFlags 필터 플래그를 사용하여 검색에 포함할 속성을 정의할 수 있습니다.

  • 반환을 얻으려면 BindingFlags.Instance 또는 BindingFlags.Static 중 하나를 지정해야 합니다.
  • 검색에 공용 속성을 포함하도록 지정 BindingFlags.Public 합니다.
  • 검색에 public이 아닌 속성(즉, 프라이빗, 내부 및 보호된 속성)을 포함하도록 지정 BindingFlags.NonPublic 합니다.
  • 위계에서 BindingFlags.FlattenHierarchypublic 정적 멤버를 포함하도록 protected을(를) 지정하세요. 상속된 클래스에서는 private 정적 멤버가 포함되지 않습니다.

다음 BindingFlags 한정자 플래그를 사용하여 검색 작동 방식을 변경할 수 있습니다.

  • BindingFlags.IgnoreCase의 대소문자를 무시합니다.
  • BindingFlags.DeclaredOnly 단순히 상속된 속성을 검색하지 않고 Type에 선언된 속성만 검색합니다.

발생하는 상황에는 AmbiguousMatchException 다음이 포함됩니다.

  • 형식에는 이름이 같지만 매개 변수 수가 다른 두 개의 인덱싱된 속성이 포함됩니다. 모호성을 해결하려면 매개 변수 형식을 지정하는 메서드의 GetProperty 오버로드를 사용합니다.
  • 파생된 형식은 new 한정자(Shadows Visual Basic)를 사용하여 동일한 이름의 상속된 속성을 숨기는 속성을 선언합니다. 모호성을 해결하려면 상속되지 않은 멤버로 검색을 제한하도록 포함합니다 BindingFlags.DeclaredOnly .

GetProperty(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Type, System.Type[], System.Reflection.ParameterModifier[]) 메서드

기본 바인더는 ParameterModifier를 처리하지 않지만 (modifiers 매개 변수) 추상 System.Reflection.Binder 클래스를 사용하여 modifiers를 처리하는 사용자 지정 바인더를 작성할 수 있습니다. ParameterModifier 는 COM interop을 통해 호출할 때만 사용되며 참조로 전달되는 매개 변수만 처리됩니다.

다음 표에서는 형식을 반영할 때 메서드에서 반환되는 기본 클래스의 Get 멤버를 보여 줍니다.

멤버 형식 정적 비정적
생성자 No No
Field No 예. 필드는 항상 이름과 서명을 기준으로 숨겨집니다.
Event 적용할 수 없음 일반적인 형식 시스템 규칙은 상속이 속성을 구현하는 메서드의 상속과 동일하다는 것입니다. 반영은 속성을 이름 및 서명에 따라 숨김 처리합니다. 2
Method No 예. 메서드(가상 및 가상이 아닌 메서드)는 이름으로 숨기기 또는 이름과 서명으로 숨기기가 가능합니다.
중첩 타입 No No
Property 적용할 수 없음 일반적인 형식 시스템 규칙은 상속이 속성을 구현하는 메서드의 상속과 동일하다는 것입니다. 반영은 속성을 이름 및 서명에 따라 숨김 처리합니다. 2

Notes:

  • 이름별 및 서명에 의한 숨기기는 사용자 지정 한정자, 반환 형식, 매개 변수 형식, 센티넬 및 비관리 호출 규칙을 포함하여 서명의 모든 부분을 고려합니다. 이진 비교입니다.
  • 리플렉션의 경우 속성과 이벤트는 이름 및 서명별로 숨겨집니다. 기본 클래스에 get 및 set 접근자가 모두 있는 속성이 있지만 파생 클래스에 get 접근자만 있는 경우 파생 클래스 속성은 기본 클래스 속성을 숨기며 기본 클래스의 setter에 액세스할 수 없습니다.
  • 사용자 지정 특성은 공용 형식 시스템의 일부가 아닙니다.

다음 BindingFlags 필터 플래그를 사용하여 검색에 포함할 속성을 정의할 수 있습니다.

  • 반환을 얻으려면 BindingFlags.Instance 또는 BindingFlags.Static 중 하나를 지정해야 합니다.
  • 검색에 공용 속성을 포함하도록 지정 BindingFlags.Public 합니다.
  • 검색에 public이 아닌 속성(즉, 프라이빗, 내부 및 보호된 속성)을 포함하도록 지정 BindingFlags.NonPublic 합니다.
  • 위계에서 BindingFlags.FlattenHierarchypublic 정적 멤버를 포함하도록 protected을(를) 지정하세요. 상속된 클래스에서는 private 정적 멤버가 포함되지 않습니다.

다음 BindingFlags 한정자 플래그를 사용하여 검색 작동 방식을 변경할 수 있습니다.

  • BindingFlags.IgnoreCase의 대소문자를 무시합니다.
  • BindingFlags.DeclaredOnly 단순히 상속된 속성을 검색하지 않고 Type에 선언된 속성만 검색합니다.

인덱서 및 기본 속성

Visual Basic, C# 및 C++에는 인덱싱된 속성에 액세스하기 위한 구문이 간소화되었으며 인덱싱된 속성 하나가 해당 형식의 기본값이 되도록 허용합니다. 예를 들어 변수 myListArrayList를 참조하는 경우, Visual Basic 에서 myList[3] (myList(3) 사용)의 구문은 인덱스가 3인 요소를 검색합니다. 속성을 오버로드할 수 있습니다.

C#에서 이 기능을 인덱서라고 하며 이름으로 참조할 수 없습니다. 기본적으로 C# 인덱서는 메타데이터에 이름이 Item인 인덱싱된 속성으로 나타납니다. 그러나 클래스 라이브러리 개발자는 특성을 사용하여 IndexerNameAttribute 메타데이터에서 인덱서의 이름을 변경할 수 있습니다. 예를 들어, String 클래스에는 Chars[]이라는 이름의 인덱서가 있습니다. C# 이외의 언어를 사용하여 만든 인덱싱된 속성에는 다른 Item이름도 있을 수 있습니다.

형식에 기본 속성이 있는지 확인하려면 GetCustomAttributes(Type, Boolean) 메서드를 사용하여 DefaultMemberAttribute 특성을 테스트합니다. 형식 DefaultMemberAttribute이 있는 경우 속성은 MemberName 기본 속성의 이름을 반환합니다.

추가 정보

적용 대상

GetProperty(String, Type, Type[], ParameterModifier[])

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

매개 변수가 지정된 인수 형식 및 한정자와 일치하는 지정된 public 속성을 검색합니다.

public:
 System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ types, cli::array <System::Reflection::ParameterModifier> ^ modifiers);
public:
 virtual System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, Type ^ returnType, cli::array <Type ^> ^ types, cli::array <System::Reflection::ParameterModifier> ^ modifiers);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
public System.Reflection.PropertyInfo? GetProperty(string name, Type? returnType, Type[] types, System.Reflection.ParameterModifier[]? modifiers);
public System.Reflection.PropertyInfo GetProperty(string name, Type returnType, Type[] types, System.Reflection.ParameterModifier[] modifiers);
public System.Reflection.PropertyInfo? GetProperty(string name, Type? returnType, Type[] types, System.Reflection.ParameterModifier[]? modifiers);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)>]
member this.GetProperty : string * Type * Type[] * System.Reflection.ParameterModifier[] -> System.Reflection.PropertyInfo
member this.GetProperty : string * Type * Type[] * System.Reflection.ParameterModifier[] -> System.Reflection.PropertyInfo
abstract member GetProperty : string * Type * Type[] * System.Reflection.ParameterModifier[] -> System.Reflection.PropertyInfo
override this.GetProperty : string * Type * Type[] * System.Reflection.ParameterModifier[] -> System.Reflection.PropertyInfo
Public Function GetProperty (name As String, returnType As Type, types As Type(), modifiers As ParameterModifier()) As PropertyInfo

매개 변수

name
String

가져올 public 속성의 이름을 포함하는 문자열입니다.

returnType
Type

속성의 반환 형식입니다.

types
Type[]

가져올 인덱싱된 속성에 Type 대한 매개 변수의 수, 순서 및 형식을 나타내는 개체의 배열입니다.

-또는-

인덱싱되지 않은 속성을 가져오는 형식 Type 의 빈 배열(즉, Type[] types = new Type[0])입니다.

modifiers
ParameterModifier[]

배열의 ParameterModifier 해당 요소와 연결된 특성을 나타내는 개체의 types 배열입니다. 기본 바인더는 이 매개 변수를 처리하지 않습니다.

반품

지정된 요구 사항과 일치하는 public 속성을 나타내는 개체입니다(있는 경우). 그렇지 않으면 . null

구현

특성

예외

지정된 이름과 지정된 인수 형식 및 한정자와 일치하는 두 개 이상의 속성이 있습니다.

namenull입니다.

-또는-

typesnull입니다.

types 가 다차원입니다.

-또는-

modifiers 가 다차원입니다.

-또는-

types 길이 modifiers 가 같지 않습니다.

types 요소는 .입니다 null.

예제

다음 예제에서는 해당 Type개체를 MyPropertyClass 가져오고 이 클래스의 인덱싱된 속성은 메서드에 전달된 인수를 사용하여 검색됩니다GetProperty.

using System;
using System.Reflection;

public class MyPropertyClass
{
    private readonly int [,] _myPropertyArray = new int[10,10];
    // Declare an indexer.
    public int this [int i,int j]
    {
        get
        {
            return _myPropertyArray[i,j];
        }
        set
        {
            _myPropertyArray[i,j] = value;
        }
    }
}

public class MyTypeClass
{
    public static void Main()
    {
        try
        {
            Type myType=typeof(MyPropertyClass);
            Type[] myTypeArray = new Type[2];

            // Create an instance of the Type array representing the number, order
            // and type of the parameters for the property.
            myTypeArray.SetValue(typeof(int),0);
            myTypeArray.SetValue(typeof(int),1);

            // Search for the indexed property whose parameters match the
            // specified argument types and modifiers.
            PropertyInfo myPropertyInfo = myType.GetProperty("Item",
                typeof(int),myTypeArray,null);
            Console.WriteLine(myType.FullName + "." + myPropertyInfo.Name +
                " has a property type of " + myPropertyInfo.PropertyType);
         }
        catch(Exception ex)
        {
            Console.WriteLine("An exception occurred " + ex.Message);
        }
    }
}
open System

type MyPropertyClass() =
    let myPropertyArray = Array2D.zeroCreate<int> 10 10
    // Declare an indexed property.
    member _.Item
        with get (i, j) =
            myPropertyArray[i, j]
        and set (i, j) value =
            myPropertyArray[i, j] <- value

try
    let myType = typeof<MyPropertyClass>
    let myTypeArray = Array.zeroCreate<Type> 2
    // Create an instance of the Type array representing the number, order
    // and type of the parameters for the property.
    myTypeArray.SetValue(typeof<int>, 0)
    myTypeArray.SetValue(typeof<int>, 1)
    // Search for the indexed property whose parameters match the
    // specified argument types and modifiers.
    let myPropertyInfo = myType.GetProperty("Item", typeof<int>, myTypeArray, null)
    printfn $"{myType.FullName}.{myPropertyInfo.Name} has a property type of {myPropertyInfo.PropertyType}"
with ex ->
    printfn $"An exception occurred {ex.Message}"
Imports System.Reflection

Public Class MyPropertyClass
    Private myPropertyArray(9, 9) As Integer
    ' Declare an indexer.
    Default Public Property Item(ByVal i As Integer, ByVal j As Integer) As Integer
        Get
            Return myPropertyArray(i, j)
        End Get
        Set(ByVal Value As Integer)
            myPropertyArray(i, j) = Value
        End Set
    End Property
End Class

Public Class MyTypeClass21
    Public Shared Sub Run()
        Try
            Dim myType As Type = GetType(MyPropertyClass)
            Dim myTypeArray(1) As Type
            ' Create an instance of a Type array representing the number, order 
            ' and type of the parameters for the property.
            myTypeArray.SetValue(GetType(Integer), 0)
            myTypeArray.SetValue(GetType(Integer), 1)
            ' Search for the indexed property whose parameters match the
            ' specified argument types and modifiers.
            Dim myPropertyInfo As PropertyInfo = myType.GetProperty("Item",
                  GetType(Integer), myTypeArray, Nothing)
            Console.WriteLine(myType.FullName + "." + myPropertyInfo.Name +
                  " has a property  type of " + myPropertyInfo.PropertyType.ToString())
        Catch ex As Exception
            Console.WriteLine("An exception occurred " + ex.Message.ToString())
        End Try
    End Sub
End Class

설명

속성은 공용 접근자가 하나 이상 있으면 리플렉션에서 공용으로 간주됩니다. 그렇지 않으면 속성이 프라이빗으로 간주되며, 속성을 얻으려면 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static를 사용해야 합니다 (Visual Basic에서는 Or를 사용하여 값을 결합합니다).

기본 바인더는 ParameterModifier를 처리하지 않지만 (modifiers 매개 변수) 추상 System.Reflection.Binder 클래스를 사용하여 modifiers를 처리하는 사용자 지정 바인더를 작성할 수 있습니다. ParameterModifier 는 COM interop을 통해 호출할 때만 사용되며 참조로 전달되는 매개 변수만 처리됩니다.

검색에서 name은 대/소문자를 구분합니다. 검색에는 공용 정적 및 공용 인스턴스 속성이 포함됩니다.

현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 메서드는 적절한 형식 인수로 대체된 형식 매개 변수를 반환 PropertyInfo 합니다.

현재 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 메서드는 클래스 제약 조건의 속성을 검색합니다.

추가 정보

적용 대상

GetProperty(String, Type[])

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

매개 변수가 지정된 인수 형식과 일치하는 지정된 public 속성을 검색합니다.

public:
 System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, cli::array <Type ^> ^ types);
public:
 virtual System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, cli::array <Type ^> ^ types);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
public System.Reflection.PropertyInfo? GetProperty(string name, Type[] types);
public System.Reflection.PropertyInfo GetProperty(string name, Type[] types);
public System.Reflection.PropertyInfo? GetProperty(string name, Type[] types);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)>]
member this.GetProperty : string * Type[] -> System.Reflection.PropertyInfo
member this.GetProperty : string * Type[] -> System.Reflection.PropertyInfo
abstract member GetProperty : string * Type[] -> System.Reflection.PropertyInfo
override this.GetProperty : string * Type[] -> System.Reflection.PropertyInfo
Public Function GetProperty (name As String, types As Type()) As PropertyInfo

매개 변수

name
String

가져올 public 속성의 이름을 포함하는 문자열입니다.

types
Type[]

가져올 인덱싱된 속성에 Type 대한 매개 변수의 수, 순서 및 형식을 나타내는 개체의 배열입니다.

-또는-

인덱싱되지 않은 속성을 가져오는 형식 Type 의 빈 배열(즉, Type[] types = new Type[0])입니다.

반품

매개 변수가 지정된 인수 형식과 일치하는 public 속성을 나타내는 개체입니다(있는 경우). 그렇지 않으면 . null

구현

특성

예외

지정된 이름과 지정된 인수 형식과 일치하는 속성이 두 개 이상 있습니다.

namenull입니다.

-또는-

typesnull입니다.

types 가 다차원입니다.

types 요소는 .입니다 null.

예제

다음 예제에서는 사용자 정의 클래스의 개체를 검색 Type 하고, 해당 클래스의 속성을 검색하고, 전달된 인수에 지정된 속성의 속성 이름과 형식을 GetProperty표시합니다.


using System;
using System.Reflection;

class MyClass3
{
    private readonly int[,] _myArray = { { 1, 2 }, { 3, 4 } };
    // Declare an indexer.
    public int this[int i, int j]
    {
        get
        {
            return _myArray[i, j];
        }
        set
        {
            _myArray[i, j] = value;
        }
    }
}

public class MyTypeClass3
{
    public static void Main(string[] args)
    {
        try
        {
            // Get the Type object.
            Type myType = typeof(MyClass3);
            Type[] myTypeArr = new Type[2];

            // Create an instance of a Type array.
            myTypeArr.SetValue(typeof(int), 0);
            myTypeArr.SetValue(typeof(int), 1);

            // Get the PropertyInfo object for the indexed property Item, which has two integer parameters.
            PropertyInfo myPropInfo = myType.GetProperty("Item", myTypeArr);

            // Display the property.
            Console.WriteLine("The {0} property exists in MyClass3.",
                myPropInfo.ToString());
        }
        catch (NullReferenceException e)
        {
            Console.WriteLine("An exception occurred.");
            Console.WriteLine("Source : {0}", e.Source);
            Console.WriteLine("Message : {0}", e.Message);
        }
    }
}
open System

type MyClass1() =
    let myArray = array2D [[1; 2]; [3; 4]]
    // Declare an indexed property.
    member _.Item
        with get (i, j) =
            myArray[i, j]
        and set (i, j) value =
            myArray[i, j] <- value
try
    // Get the Type object.
    let myType = typeof<MyClass1>
    let myTypeArr = Array.zeroCreate<Type> 2
    // Create an instance of a Type array.
    myTypeArr.SetValue(typeof<int>, 0)
    myTypeArr.SetValue(typeof<int>, 1)
    // Get the PropertyInfo object for the indexed property Item, which has two integer parameters.
    let myPropInfo = myType.GetProperty("Item", myTypeArr)
    // Display the property.
    printfn $"The {myPropInfo} property exists in MyClass1."
with :? NullReferenceException as e ->
    printfn "An exception occurred."
    printfn $"Source : {e.Source}" 
    printfn $"Message : {e.Message}"
Imports System.Reflection

Module Module3
    Class MyClass3
        Private myArray As Integer(,) = {{1, 2}, {3, 4}}
        ' Declare an indexer.
        Default Public Property Item(ByVal i As Integer, ByVal j As Integer) As Integer
            Get
                Return myArray(i, j)
            End Get
            Set(ByVal Value As Integer)

                myArray(i, j) = Value
            End Set
        End Property
    End Class

    Public Class MyTypeClass3
        Public Shared Sub Run()
            Try
                ' Get the Type Object.
                Dim myType As Type = GetType(MyClass3)
                Dim myTypeArr(1) As Type
                ' Create an instance of a Type array.
                myTypeArr.SetValue(GetType(Integer), 0)
                myTypeArr.SetValue(GetType(Integer), 1)
                ' Get the PropertyInfo object for the indexed property Item, which has two integer parameters. 
                Dim myPropInfo As PropertyInfo = myType.GetProperty("Item", myTypeArr)
                ' Display the property.
                Console.WriteLine("The {0} property exists in MyClass3.", myPropInfo.ToString())
            Catch e As NullReferenceException
                Console.WriteLine("An exception occurred.")
                Console.WriteLine("Source : {0}", e.Source.ToString())
                Console.WriteLine("Message : {0}", e.Message.ToString())
            End Try
        End Sub
    End Class
End Module 'Module3

설명

속성은 공용 접근자가 하나 이상 있으면 리플렉션에서 공용으로 간주됩니다. 그렇지 않으면 속성이 프라이빗으로 간주되며, 속성을 얻으려면 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static를 사용해야 합니다 (Visual Basic에서는 Or를 사용하여 값을 결합합니다).

검색에서 name은 대/소문자를 구분합니다. 검색에는 공용 정적 및 공용 인스턴스 속성이 포함됩니다.

현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 메서드는 적절한 형식 인수로 대체된 형식 매개 변수를 반환 PropertyInfo 합니다.

현재 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 메서드는 클래스 제약 조건의 속성을 검색합니다.

추가 정보

적용 대상

GetProperty(String, Type)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

지정된 이름과 반환 형식을 사용하여 public 속성을 검색합니다.

public:
 System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, Type ^ returnType);
public:
 virtual System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, Type ^ returnType);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
public System.Reflection.PropertyInfo? GetProperty(string name, Type? returnType);
public System.Reflection.PropertyInfo GetProperty(string name, Type returnType);
public System.Reflection.PropertyInfo? GetProperty(string name, Type? returnType);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)>]
member this.GetProperty : string * Type -> System.Reflection.PropertyInfo
member this.GetProperty : string * Type -> System.Reflection.PropertyInfo
abstract member GetProperty : string * Type -> System.Reflection.PropertyInfo
override this.GetProperty : string * Type -> System.Reflection.PropertyInfo
Public Function GetProperty (name As String, returnType As Type) As PropertyInfo

매개 변수

name
String

가져올 public 속성의 이름을 포함하는 문자열입니다.

returnType
Type

속성의 반환 형식입니다.

반품

지정된 이름을 가진 public 속성을 나타내는 개체입니다(있는 경우). 그렇지 않으면 . null

구현

특성

예외

지정된 이름으로 둘 이상의 속성을 찾습니다.

예제

다음 예제에서는 하나의 속성이 있는 클래스를 정의하고 속성의 이름과 형식을 검색합니다.


using System;
using System.Reflection;

class MyPropertyTypeClass
{
    public string MyProperty1 { get; set; } = "Hello World.";
}

class TestClass
{
    static void Main()
    {
        try
        {
            Type myType = typeof(MyPropertyTypeClass);

            // Get the PropertyInfo object representing MyProperty1.
            PropertyInfo myStringProperties1 = myType.GetProperty("MyProperty1", typeof(string));

            Console.WriteLine("The name of the first property of MyPropertyTypeClass is {0}.",
                myStringProperties1.Name);
            Console.WriteLine("The type of the first property of MyPropertyTypeClass is {0}.",
                myStringProperties1.PropertyType);
        }
        catch (ArgumentNullException e)
        {
            Console.WriteLine("ArgumentNullException :" + e.Message);
        }
        catch (AmbiguousMatchException e)
        {
            Console.WriteLine("AmbiguousMatchException :" + e.Message);
        }
        catch (NullReferenceException e)
        {
            Console.WriteLine("Source : {0}", e.Source);
            Console.WriteLine("Message : {0}", e.Message);
        }
        //Output:
        //The name of the first property of MyPropertyTypeClass is MyProperty1.
        //The type of the first property of MyPropertyTypeClass is System.String.
    }
}
open System
open System.Reflection

type MyClass1() =
    let mutable myMessage = "Hello World."
    member _.MyProperty1 
        with get () =
            myMessage
        and set (value) =
            myMessage <- value

try
    let myType = typeof<MyClass1>
    // Get the PropertyInfo object representing MyProperty1.
    let myStringProperties1 = myType.GetProperty("MyProperty1", typeof<string>)
    printfn $"The name of the first property of MyClass1 is {myStringProperties1.Name}."
    printfn $"The type of the first property of MyClass1 is {myStringProperties1.PropertyType}."
with
| :? ArgumentNullException as e ->
    printfn $"ArgumentNullException :{e.Message}"
| :? AmbiguousMatchException as e ->
    printfn $"AmbiguousMatchException :{e.Message}"
| :? NullReferenceException as e ->
    printfn $"Source : {e.Source}"
    printfn $"Message : {e.Message}"
// Output:
//     The name of the first property of MyClass1 is MyProperty1.
//     The type of the first property of MyClass1 is System.String.
Imports System.Reflection
Class MyTypesClass
    Private myMessage As [String] = "Hello World."
    Public Property MyProperty1() As String
        Get
            Return myMessage
        End Get
        Set(ByVal Value As String)
            myMessage = Value
        End Set
    End Property
End Class

Class TestClass
    Shared Sub Run()
        Try
            Dim myType As Type = GetType(MyTypesClass)
            ' Get the PropertyInfo object representing MyProperty1. 
            Dim myStringProperties1 As PropertyInfo = myType.GetProperty("MyProperty1", GetType(String))
            Console.WriteLine("The name of the first property of MyTypesClass is {0}.", myStringProperties1.Name)
            Console.WriteLine("The type of the first property of MyTypesClass is {0}.", myStringProperties1.PropertyType.ToString())
        Catch e As ArgumentNullException
            Console.WriteLine("ArgumentNullException :" + e.Message.ToString())
        Catch e As AmbiguousMatchException
            Console.WriteLine("AmbiguousMatchException :" + e.Message.ToString())
        Catch e As NullReferenceException
            Console.WriteLine("Source : {0}", e.Source.ToString())
            Console.WriteLine("Message : {0}", e.Message.ToString())
        End Try

        'Output:
        'The name of the first property of MyTypesClass is MyProperty1.
        'The type of the first property of MyTypesClass is System.String.
    End Sub
End Class

설명

속성은 공용 접근자가 하나 이상 있으면 리플렉션에서 공용으로 간주됩니다. 그렇지 않으면 속성이 프라이빗으로 간주되며, 속성을 얻으려면 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static를 사용해야 합니다 (Visual Basic에서는 Or를 사용하여 값을 결합합니다).

검색에서 name은 대/소문자를 구분합니다. 검색에는 공용 정적 및 공용 인스턴스 속성이 포함됩니다.

현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 메서드는 적절한 형식 인수로 대체된 형식 매개 변수를 반환 PropertyInfo 합니다.

현재 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 메서드는 클래스 제약 조건의 속성을 검색합니다.

추가 정보

적용 대상

GetProperty(String, BindingFlags)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

지정된 바인딩 제약 조건을 사용하여 지정된 속성을 검색합니다.

public:
 virtual System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name, System::Reflection::BindingFlags bindingAttr);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicProperties | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
public System.Reflection.PropertyInfo? GetProperty(string name, System.Reflection.BindingFlags bindingAttr);
public System.Reflection.PropertyInfo GetProperty(string name, System.Reflection.BindingFlags bindingAttr);
public System.Reflection.PropertyInfo? GetProperty(string name, System.Reflection.BindingFlags bindingAttr);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicProperties | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)>]
abstract member GetProperty : string * System.Reflection.BindingFlags -> System.Reflection.PropertyInfo
override this.GetProperty : string * System.Reflection.BindingFlags -> System.Reflection.PropertyInfo
abstract member GetProperty : string * System.Reflection.BindingFlags -> System.Reflection.PropertyInfo
override this.GetProperty : string * System.Reflection.BindingFlags -> System.Reflection.PropertyInfo
Public Function GetProperty (name As String, bindingAttr As BindingFlags) As PropertyInfo

매개 변수

name
String

가져올 속성의 이름을 포함하는 문자열입니다.

bindingAttr
BindingFlags

검색을 수행하는 방법을 지정하는 열거형 값의 비트 조합입니다.

-또는-

Default 를 반환 null합니다.

반품

지정된 요구 사항과 일치하는 속성을 나타내는 개체입니다(있는 경우). 그렇지 않으면 . null

구현

특성

예외

지정된 이름과 지정된 바인딩 제약 조건과 일치하는 두 개 이상의 속성이 있습니다.

namenull입니다.

예제

다음 예제에서는 사용자 정의 클래스의 형식을 검색하고, 해당 클래스의 속성을 검색하고, 지정된 바인딩 제약 조건에 따라 속성 이름을 표시합니다.


using System;
using System.Reflection;

class MyClass2
{
    // Declare MyProperty.
    public int MyProperty { get; set; }
}

public class MyTypeClass2
{
    public static void Main(string[] args)
    {
        try
        {
            // Get Type object of MyClass2.
            Type myType = typeof(MyClass2);

            // Get the PropertyInfo by passing the property name and specifying the BindingFlags.
            PropertyInfo myPropInfo = myType.GetProperty(
                "MyProperty",
                BindingFlags.Public | BindingFlags.Instance
                );

            // Display Name property to console.
            Console.WriteLine("{0} is a property of MyClass2.", myPropInfo.Name);
        }
        catch (NullReferenceException e)
        {
            Console.WriteLine("MyProperty does not exist in MyClass2." + e.Message);
        }
    }
}
open System
open System.Reflection

type MyClass() =
    let mutable myProperty = 0
    // Declare MyProperty.
    member _.MyProperty
        with get () =
            myProperty
        and set (value) =
            myProperty <- value

try
    // Get Type object of MyClass.
    let myType = typeof<MyClass>
    // Get the PropertyInfo by passing the property name and specifying the BindingFlags.
    let myPropInfo = myType.GetProperty("MyProperty", BindingFlags.Public ||| BindingFlags.Instance)
    // Display Name property to console.
    printfn $"{myPropInfo.Name} is a property of MyClass."
with :? NullReferenceException as e ->
    printfn $"MyProperty does not exist in MyClass.{e.Message}"

Imports System.Reflection
Module Module1
    Public Class MyClass1
        Private myProperty1 As Integer

        Public Property MyProperty() As Integer
            Get
                Return myProperty1
            End Get
            Set(ByVal Value As Integer)
                myProperty1 = Value
            End Set
        End Property

        Public Shared Sub Run()
            Try
                ' Get a Type object corresponding to MyClass.
                Dim myType As Type = GetType(MyClass1)
                ' Get a PropertyInfo object by passing property name and specifying BindingFlags.
                Dim myPropInfo As PropertyInfo = myType.GetProperty("MyProperty", BindingFlags.Public Or BindingFlags.Instance)
                ' Display the Name property.
                Console.WriteLine("{0} is a property of MyClass.", myPropInfo.Name)
            Catch e As NullReferenceException
                Console.WriteLine("MyProperty does not exist in MyClass.", e.Message.ToString())
            End Try
        End Sub
    End Class
End Module 'Module1

추가 정보

적용 대상

GetProperty(String)

Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs
Source:
Type.cs

지정된 이름의 public 속성을 검색합니다.

public:
 System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name);
public:
 virtual System::Reflection::PropertyInfo ^ GetProperty(System::String ^ name);
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)]
public System.Reflection.PropertyInfo? GetProperty(string name);
public System.Reflection.PropertyInfo GetProperty(string name);
public System.Reflection.PropertyInfo? GetProperty(string name);
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)>]
member this.GetProperty : string -> System.Reflection.PropertyInfo
member this.GetProperty : string -> System.Reflection.PropertyInfo
abstract member GetProperty : string -> System.Reflection.PropertyInfo
override this.GetProperty : string -> System.Reflection.PropertyInfo
Public Function GetProperty (name As String) As PropertyInfo

매개 변수

name
String

가져올 public 속성의 이름을 포함하는 문자열입니다.

반품

지정된 이름을 가진 public 속성을 나타내는 개체입니다(있는 경우). 그렇지 않으면 . null

구현

특성

예외

지정된 이름으로 둘 이상의 속성을 찾습니다.

namenull입니다.

예제

다음 예제에서는 사용자 정의 클래스의 개체를 검색 Type 하 고 해당 클래스의 속성을 검색 하 고 속성 이름을 표시 합니다.

using System;
using System.Reflection;

class MyClass1
{
    // Declare MyProperty.
    public int MyProperty { get; set; }
}

public class MyTypeClass1
{
    public static void Main(string[] args)
    {
        try
        {
            // Get the Type object corresponding to MyClass1.
            Type myType = typeof(MyClass1);

            // Get the PropertyInfo object by passing the property name.
            PropertyInfo myPropInfo = myType.GetProperty("MyProperty");

            // Display the property name.
            Console.WriteLine("The {0} property exists in MyClass1.", myPropInfo.Name);
        }
        catch (NullReferenceException e)
        {
            Console.WriteLine("The property does not exist in MyClass1." + e.Message);
        }
    }
}
open System

type MyClass() =
    let mutable myProperty = 0
    // Declare MyProperty.
    member _.MyProperty
        with get () =
            myProperty
        and set (value) = 
            myProperty <- value

try
    // Get the Type object corresponding to MyClass.
    let myType = typeof<MyClass>
    // Get the PropertyInfo object by passing the property name.
    let myPropInfo = myType.GetProperty "MyProperty"
    // Display the property name.
    printfn $"The {myPropInfo.Name} property exists in MyClass."
with :? NullReferenceException as e ->
    printfn $"The property does not exist in MyClass.{e.Message}"
Imports System.Reflection
Class MyClass1
    Private myProperty1 As Integer
    ' Declare MyProperty.

    Public Property MyProperty() As Integer
        Get
            Return MyProperty1
        End Get
        Set(ByVal Value As Integer)
            MyProperty1 = Value
        End Set
    End Property
End Class

Public Class MyTypeClass
    Public Shared Sub Run(ByVal args() As String)
        Try
            ' Get Type Object corresponding to MyClass.
            Dim myType As Type = GetType(MyClass1)
            ' Get PropertyInfo object by passing property name.
            Dim myPropInfo As PropertyInfo = myType.GetProperty("MyProperty")
            ' Display Name property to console.
            Console.WriteLine("The {0} property exists in MyClass.", myPropInfo.Name)
        Catch e As NullReferenceException
            Console.WriteLine("The property does not exist in MyClass.", e.Message.ToString())
        End Try
    End Sub
End Class

설명

다음 지침은 모든 오버로드에 적용됩니다.

  • 속성은 공용 접근자가 하나 이상 있으면 리플렉션에서 공용으로 간주됩니다. 그렇지 않으면 속성이 프라이빗으로 간주되며, 속성을 얻으려면 BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static를 사용해야 합니다 (Visual Basic에서는 Or를 사용하여 값을 결합합니다).
  • 현재 Type 가 생성된 제네릭 형식을 나타내는 경우 이 메서드는 적절한 형식 인수로 대체된 형식 매개 변수를 반환 PropertyInfo 합니다.
  • 현재 Type 제네릭 형식 또는 제네릭 메서드 정의에서 형식 매개 변수를 나타내는 경우 이 메서드는 클래스 제약 조건의 속성을 검색합니다.

GetProperty(String) 메서드

검색에서 name은 대/소문자를 구분합니다. 검색에는 공용 정적 및 공용 인스턴스 속성이 포함됩니다.

발생하는 상황에는 AmbiguousMatchException 다음이 포함됩니다.

  • 형식에는 이름이 같지만 매개 변수 수가 다른 두 개의 인덱싱된 속성이 포함됩니다. 모호성을 해결하려면 매개 변수 형식을 지정하는 메서드의 GetProperty 오버로드를 사용합니다.
  • 파생 형식은 new 한정자를 사용하여 동일한 이름의 상속된 속성을 가리는 속성을 선언하며, 이는 Visual Basic에서 Shadows 한정자를 사용합니다. 모호성을 해결하려면 메서드 오버로드를 GetProperty(String, BindingFlags) 사용하고 플래그를 BindingFlags.DeclaredOnly 추가하여 상속되지 않은 멤버로 검색을 제한합니다.

GetProperty(String, BindingFlags) 메서드

다음 BindingFlags 필터 플래그를 사용하여 검색에 포함할 속성을 정의할 수 있습니다.

  • 반환을 얻으려면 BindingFlags.Instance 또는 BindingFlags.Static 중 하나를 지정해야 합니다.
  • 검색에 공용 속성을 포함하도록 지정 BindingFlags.Public 합니다.
  • 검색에 public이 아닌 속성(즉, 프라이빗, 내부 및 보호된 속성)을 포함하도록 지정 BindingFlags.NonPublic 합니다.
  • 위계에서 BindingFlags.FlattenHierarchypublic 정적 멤버를 포함하도록 protected을(를) 지정하세요. 상속된 클래스에서는 private 정적 멤버가 포함되지 않습니다.

다음 BindingFlags 한정자 플래그를 사용하여 검색 작동 방식을 변경할 수 있습니다.

  • BindingFlags.IgnoreCase의 대소문자를 무시합니다.
  • BindingFlags.DeclaredOnly 단순히 상속된 속성을 검색하지 않고 Type에 선언된 속성만 검색합니다.

발생하는 상황에는 AmbiguousMatchException 다음이 포함됩니다.

  • 형식에는 이름이 같지만 매개 변수 수가 다른 두 개의 인덱싱된 속성이 포함됩니다. 모호성을 해결하려면 매개 변수 형식을 지정하는 메서드의 GetProperty 오버로드를 사용합니다.
  • 파생된 형식은 new 한정자(Shadows Visual Basic)를 사용하여 동일한 이름의 상속된 속성을 숨기는 속성을 선언합니다. 모호성을 해결하려면 상속되지 않은 멤버로 검색을 제한하도록 포함합니다 BindingFlags.DeclaredOnly .

GetProperty(System.String, System.Reflection.BindingFlags, System.Reflection.Binder, System.Type, System.Type[], System.Reflection.ParameterModifier[]) 메서드

기본 바인더는 ParameterModifier를 처리하지 않지만 (modifiers 매개 변수) 추상 System.Reflection.Binder 클래스를 사용하여 modifiers를 처리하는 사용자 지정 바인더를 작성할 수 있습니다. ParameterModifier 는 COM interop을 통해 호출할 때만 사용되며 참조로 전달되는 매개 변수만 처리됩니다.

다음 표에서는 형식을 반영할 때 메서드에서 반환되는 기본 클래스의 Get 멤버를 보여 줍니다.

멤버 형식 정적 비정적
생성자 No No
Field No 예. 필드는 항상 이름과 서명을 기준으로 숨겨집니다.
Event 적용할 수 없음 일반적인 형식 시스템 규칙은 상속이 속성을 구현하는 메서드의 상속과 동일하다는 것입니다. 반영은 속성을 이름 및 서명에 따라 숨김 처리합니다. 2
Method No 예. 메서드(가상 및 가상이 아닌 메서드)는 이름으로 숨기기 또는 이름과 서명으로 숨기기가 가능합니다.
중첩 타입 No No
Property 적용할 수 없음 일반적인 형식 시스템 규칙은 상속이 속성을 구현하는 메서드의 상속과 동일하다는 것입니다. 반영은 속성을 이름 및 서명에 따라 숨김 처리합니다. 2

Notes:

  • 이름별 및 서명에 의한 숨기기는 사용자 지정 한정자, 반환 형식, 매개 변수 형식, 센티넬 및 비관리 호출 규칙을 포함하여 서명의 모든 부분을 고려합니다. 이진 비교입니다.
  • 리플렉션의 경우 속성과 이벤트는 이름 및 서명별로 숨겨집니다. 기본 클래스에 get 및 set 접근자가 모두 있는 속성이 있지만 파생 클래스에 get 접근자만 있는 경우 파생 클래스 속성은 기본 클래스 속성을 숨기며 기본 클래스의 setter에 액세스할 수 없습니다.
  • 사용자 지정 특성은 공용 형식 시스템의 일부가 아닙니다.

다음 BindingFlags 필터 플래그를 사용하여 검색에 포함할 속성을 정의할 수 있습니다.

  • 반환을 얻으려면 BindingFlags.Instance 또는 BindingFlags.Static 중 하나를 지정해야 합니다.
  • 검색에 공용 속성을 포함하도록 지정 BindingFlags.Public 합니다.
  • 검색에 public이 아닌 속성(즉, 프라이빗, 내부 및 보호된 속성)을 포함하도록 지정 BindingFlags.NonPublic 합니다.
  • 위계에서 BindingFlags.FlattenHierarchypublic 정적 멤버를 포함하도록 protected을(를) 지정하세요. 상속된 클래스에서는 private 정적 멤버가 포함되지 않습니다.

다음 BindingFlags 한정자 플래그를 사용하여 검색 작동 방식을 변경할 수 있습니다.

  • BindingFlags.IgnoreCase의 대소문자를 무시합니다.
  • BindingFlags.DeclaredOnly 단순히 상속된 속성을 검색하지 않고 Type에 선언된 속성만 검색합니다.

인덱서 및 기본 속성

Visual Basic, C# 및 C++에는 인덱싱된 속성에 액세스하기 위한 구문이 간소화되었으며 인덱싱된 속성 하나가 해당 형식의 기본값이 되도록 허용합니다. 예를 들어 변수 myListArrayList를 참조하는 경우, Visual Basic 에서 myList[3] (myList(3) 사용)의 구문은 인덱스가 3인 요소를 검색합니다. 속성을 오버로드할 수 있습니다.

C#에서 이 기능을 인덱서라고 하며 이름으로 참조할 수 없습니다. 기본적으로 C# 인덱서는 메타데이터에 이름이 Item인 인덱싱된 속성으로 나타납니다. 그러나 클래스 라이브러리 개발자는 특성을 사용하여 IndexerNameAttribute 메타데이터에서 인덱서의 이름을 변경할 수 있습니다. 예를 들어, String 클래스에는 Chars[]이라는 이름의 인덱서가 있습니다. C# 이외의 언어를 사용하여 만든 인덱싱된 속성에는 다른 Item이름도 있을 수 있습니다.

형식에 기본 속성이 있는지 확인하려면 GetCustomAttributes(Type, Boolean) 메서드를 사용하여 DefaultMemberAttribute 특성을 테스트합니다. 형식 DefaultMemberAttribute이 있는 경우 속성은 MemberName 기본 속성의 이름을 반환합니다.

추가 정보

적용 대상