Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

Type.DefaultBinder-Eigenschaft

 

Veröffentlicht: Oktober 2016

Ruft einen Verweis auf den Standardbinder ab, der interne Regeln für die Auswahl der passenden Member implementiert, die von InvokeMember aufgerufen werden sollen.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

public static Binder DefaultBinder { get; }

Eigenschaftswert

Type: System.Reflection.Binder

Ein Verweis auf den vom System verwendeten Standardbinder.

The default binder provided with the common language runtime is applicable in all but the most specialized circumstances. If you need a binder that follows rules that differ from those of the supplied default binder, define a type derived from the T:System.Reflection.Binder class and pass an instance of that type using the binder parameter of one of the M:System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]) overloads.

Reflection models the accessibility rules of the common type system. For example, if the caller is in the same assembly, the caller does not need special permissions for internal members. Otherwise, the caller needs T:System.Security.Permissions.ReflectionPermission. This is consistent with lookup of members that are protected, private, and so on.

The general principle is that M:System.Reflection.Binder.ChangeType(System.Object,System.Type,System.Globalization.CultureInfo) should perform only widening conversions, which never lose data. An example of a widening conversion is converting a value that is a 32-bit signed integer to a value that is a 64-bit signed integer. This is distinguished from a narrowing conversion, which may lose data. An example of a narrowing conversion is converting a 64-bit signed integer to a 32-bit signed integer.

The following table lists the conversions supported by the default binder.

Source Type

Target Type

Any type

Its base type.

Any type

The interface it implements.

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

Non-reference

By-reference.

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 M:System.Type.InvokeMember(System.String,System.Reflection.BindingFlags,System.Reflection.Binder,System.Object,System.Object[],System.Reflection.ParameterModifier[],System.Globalization.CultureInfo,System.String[]).

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");
        }	
    }
}

.NET Framework
Verfügbar seit 1.1
Silverlight
Verfügbar seit 2.0
Windows Phone Silverlight
Verfügbar seit 7.0
Zurück zum Anfang
Anzeigen: