Type.DefaultBinder 속성

정의

InvokeMember(String, BindingFlags, Binder, Object, Object[], ParameterModifier[], CultureInfo, String[])에서 호출하는 적절한 멤버를 선택하기 위해 내부 규칙을 구현하는 기본 바인더에 대한 참조를 가져옵니다.

public:
 static property System::Reflection::Binder ^ DefaultBinder { System::Reflection::Binder ^ get(); };
public static System.Reflection.Binder DefaultBinder { get; }
static member DefaultBinder : System.Reflection.Binder
Public Shared ReadOnly Property DefaultBinder As Binder

속성 값

시스템에서 사용되는 기본 바인더에 대한 참조입니다.

예제

다음 예제에서는 속성에서 기본 바인더를 DefaultBinder 가져오고 값을 매개 변수InvokeMember로 에 전달 DefaultBinder 하여 MyClass의 멤버를 호출합니다.

using namespace System;
using namespace System::Reflection;
ref class MyClass
{
public:
   void HelloWorld()
   {
      Console::WriteLine( "Hello World" );
   }

};

int main()
{
   try
   {
      Binder^ defaultBinder = Type::DefaultBinder;
      MyClass^ myClass = gcnew MyClass;
      
      // Invoke the HelloWorld method of MyClass.
      myClass->GetType()->InvokeMember( "HelloWorld", BindingFlags::InvokeMethod, defaultBinder, myClass, nullptr );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception : {0}", e->Message );
   }

}
using System;
using System.Reflection;

public class MyDefaultBinderSample
{
    public static void Main()
    {
        try
        {
            Binder defaultBinder = Type.DefaultBinder;
            MyClass myClass = new MyClass();
            // Invoke the HelloWorld method of MyClass.
            myClass.GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod,
                defaultBinder, myClass, new object [] {});
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception :" + e.Message);
        }
    }	

    class MyClass
    {
        public void HelloWorld()
        {
            Console.WriteLine("Hello World");
        }	
    }
}
open System
open System.Reflection

type MyClass() =
    member _.HelloWorld() =
        printfn "Hello World"

try
    let defaultBinder = Type.DefaultBinder
    let myClass = MyClass()
    // Invoke the HelloWorld method of MyClass.
    myClass.GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod, defaultBinder, myClass, [||])
    |> ignore
with e ->
    printfn $"Exception: {e.Message}"
Imports System.Reflection

Public Class MyDefaultBinderSample
    Public Shared Sub Main()
        Try
            Dim defaultBinder As Binder = Type.DefaultBinder
            Dim [myClass] As New [MyClass]()
            ' Invoke the HelloWorld method of MyClass.
            [myClass].GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod, defaultBinder, [myClass], New Object() {})
        Catch e As Exception
            Console.WriteLine("Exception :" + e.Message.ToString())
        End Try
    End Sub

    Class [MyClass]

        Public Sub HelloWorld()
            Console.WriteLine("Hello World")
        End Sub
    End Class
End Class

설명

공용 언어 런타임과 함께 제공되는 기본 바인더는 가장 특수화된 상황을 제외한 모든 경우에 적용됩니다. 제공된 기본 바인더와 다른 규칙을 따르는 바인더가 필요한 경우 클래스에서 Binder 파생된 형식을 정의하고 오버로드 중 하나의 매개 변수를 사용하여 binder 해당 형식의 인스턴스를 InvokeMember 전달합니다.

리플렉션은 공통 형식 시스템의 접근성 규칙을 모델링합니다. 예를 들어 호출자가 동일한 어셈블리에 있는 경우 호출자는 내부 멤버에 대한 특별한 권한이 필요하지 않습니다. 그렇지 않으면 호출자에게 가 필요합니다 ReflectionPermission. 이는 보호되는 멤버, 프라이빗 등의 멤버 조회와 일치합니다.

일반적인 원칙은 ChangeType 데이터를 잃지 않는 확대 변환만 수행해야 한다는 것입니다. 확대 변환의 예는 32비트 부제 정수인 값을 64비트 부제 정수 값으로 변환하는 것입니다. 이는 데이터가 손실될 수 있는 축소 변환과 구별됩니다. 축소 변환의 예로는 부 서명된 64비트 정수를 32비트 부제 정수로 변환하는 것이 있습니다.

다음 표에서는 기본 바인더에서 지원하는 변환을 나열합니다.

원본 유형 대상 유형
모든 형식 기본 형식입니다.
모든 형식 구현하는 인터페이스입니다.
Char Unt16, UInt32, Int32, UInt64, Int64, Single, Double
Byte Char, Unt16, Int16, UInt32, Int32, UInt64, Int64, Single, Double
SByte Int16, Int32, Int64, Single, Double
UInt16 UInt32, Int32, UInt64, Int64, Single, Double
Int16 Int32, Int64, Single, Double
UInt32 UInt64, Int64, Single, Double
Int32 Int64, Single, Double
UInt64 Single, Double
Int64 Single, Double
Single Double
참조가 아닌 경우 참조 기준입니다.

적용 대상

추가 정보