Type.DefaultBinder プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > Type.DefaultBinder プロパティの意味・解説 

Type.DefaultBinder プロパティ

既定のバインダへの参照を取得します。このバインダは、InvokeMember によって呼び出される適切なメンバを選択するための内部規則を実装します。

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

解説解説

共通言語ランタイムと共に提供される既定のバインダは、非常に特殊な場合を除くすべての状況で適用できます。用意されている既定のバインダの規則とは異なる規則に従うバインダが必要な場合は、Binder クラスから派生した型を定義し、InvokeMember オーバーロードのいずれかの binder パラメータを使用して、その型のインスタンスを渡します。

リフレクションは、共通型システムにおけるアクセスに関する規則をモデル化します。たとえば、呼び出し元が同一アセンブリ内にある場合、呼び出し元に内部メンバに対する特別なアクセス許可は必要ありません。それ以外の場合は、呼び出し元に 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

非参照渡し

参照渡し

使用例使用例

DefaultBinder プロパティから既定のバインダを取得し、InvokeMember へのパラメータとして DefaultBinder の値を渡して、MyClass のメンバを実行する例を次に示します。

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

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 'Main

    Class [MyClass]

        Public Sub HelloWorld()
            Console.WriteLine("Hello World")
        End Sub 'HelloWorld
    End Class '[MyClass]
End Class 'MyDefaultBinderSample
 
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");
        }    
    }
}
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 );
   }

}

import System.*;
import System.Reflection.*;

public class MyDefaultBinderSample
{
    public static void main(String[]
 args)
    {
        try {
            Binder defaultBinder = Type.get_DefaultBinder();
            MyClass myClass = new MyClass();
            // Invoke the HelloWorld method of MyClass.
            myClass.GetType().InvokeMember("HelloWorld",
                BindingFlags.InvokeMethod, defaultBinder, myClass,
                new Object[] {});
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception :" + e.get_Message());
        }
    } //main

    static class MyClass
    {
        public void HelloWorld()
        {
            Console.WriteLine("Hello World");
        } //HelloWorld
    } //MyClass
} //MyDefaultBinderSample
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

Type.DefaultBinder プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Type.DefaultBinder プロパティのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS