Type.DefaultBinder プロパティ
アセンブリ: mscorlib (mscorlib.dll 内)


共通言語ランタイムと共に提供される既定のバインダは、非常に特殊な場合を除くすべての状況で適用できます。用意されている既定のバインダの規則とは異なる規則に従うバインダが必要な場合は、Binder クラスから派生した型を定義し、InvokeMember オーバーロードのいずれかの binder パラメータを使用して、その型のインスタンスを渡します。
リフレクションは、共通型システムにおけるアクセスに関する規則をモデル化します。たとえば、呼び出し元が同一アセンブリ内にある場合、呼び出し元に内部メンバに対する特別なアクセス許可は必要ありません。それ以外の場合は、呼び出し元に ReflectionPermission が必要です。このことは、プロテクト メンバ、プライベート メンバなどを検索する場合も同様です。
一般原則として、ChangeType は型の拡大変換だけを実行します。この変換では、データは失われません。拡大変換の例としては、32 ビット符号付き整数値から 64 ビット符号付き整数値への変換があります。この変換は、データが失われる可能性がある縮小変換とは区別されます。型の縮小変換の例としては、64 ビット符号付き整数から 32 ビット符号付き整数への変換があります。
既定のバインダでサポートされる変換の一覧を次の表に示します。

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からType.DefaultBinder プロパティを検索する場合は、下記のリンクをクリックしてください。

- Type.DefaultBinder プロパティのページへのリンク