See Also: Binder Members
Late binding is controlled by a customized binding interface through reflection. The System.Reflection.Binder class is designed to provide this functionality. System.Reflection.Binder objects are used in overload resolution and argument coercion for dynamic invocation of members at runtime.
Access to information obtained from reflection is controlled at two levels: untrusted code and code with System.Security.Permissions.ReflectionPermission.
Untrusted code is code with no special level of trust (such as code downloaded from the Internet). Such code is allowed to invoke anything that it would have been able to invoke in an early bound way.
System.Security.Permissions.ReflectionPermission controls access to metadata through reflection. If this permission is granted to code, that code has access to all the types in its application domain, assembly, and module. It can access information about public, family, and private members of all types it has access to. Two primary capabilities are granted:
The term "reflection" refers to the ability to obtain information about a object during runtime. The primary means through which this information is accessed is via the Type of the object. Reflection allows the programmatic discovery of a type's metadata. The information included in the metadata includes details about the assembly or module in which the type is defined as well as members of the type. Reflection uses this information to provide the following primary services:
The primary users of these services are script engines, object viewers, compilers, and object persistence formatters.
Through reflection, methods can be bound and invoked at runtime. If more than one member exists for a given member name, overload resolution determines which implementation of that method is invoked by the system. Coercion can occur when a parameter specified for a method call does not match the type specified for the parameter in the method signature. When possible, the binder converts the parameter (coerces it) to the type specified by the method signature. Coercion might not be possible depending on the types involved.
To bind to a method, field, or property, typically a list of probable candidates is obtained from the Type of a object. That list is the passed to the appropriate method of a System.Reflection.Binder instance. Based on the other parameters passed to that method, typically (although not necessarily) one of the members of the list is chosen, and an object that reflects that member is returned.
The system supplies a default binder that provides default binding rules. Because binding rules vary among programming languages, it is recommended that each programming language provide a custom implementation of System.Reflection.Binder .