C# Type DefaultBinder

Description

Type DefaultBinder gets a reference to the default binder, which implements internal rules for selecting the appropriate members to be called by InvokeMember.

Syntax

Type.DefaultBinder has the following syntax.


public static Binder DefaultBinder { get; }

Example

The following example gets the default binder from the DefaultBinder property, and invokes a member of MyClass by passing the DefaultBinder value as a parameter to InvokeMember.


using System;/*  ww  w . jav a 2s .  c  o m*/
using System.Reflection;

public class MyDefaultBinderSample
{
    public static void Main()
    {
        Binder defaultBinder = Type.DefaultBinder;
        MyClass myClass = new MyClass();
        myClass.GetType().InvokeMember("HelloWorld", BindingFlags.InvokeMethod,
                defaultBinder, myClass, new object [] {});
    }  

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

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version