Dynamic loading and usage types

Source: Internet
Author: User
Dynamic loading and usage types
Author: Microsoft China Co., Ltd.
Reflection provides underlying structures such as Microsoft Visual Basic. NET and JScript language compilers to implement implicit Post-binding. Binding is the process of locating the declaration corresponding to a specific type. This process is called Post binding when it is running, rather than compiling. Visual Basic. NET allows you to use implicit binding in your code. The Visual Basic. NET compiler calls the helper method and uses Reflection to obtain the object type. Parameters passed to the helper method enable the appropriate method to be called at runtime. These parameters are the instance of the call method (object), the name (string) of the called method, and the parameters passed to the called method. (An array of objects ).
In the following code example, the Visual Basic. NET compiler implicitly calls a method for an object of unknown type during compilation through Reflection. The HelloWorld class has a PrintHello method that can print out "Hello World" and some texts passed to the PrintHello method. In this example, the PrintHello method call is actually Type. invokeMember; Visual Basic code allows the PrintHello method to be called, as if the object type (helloObj) was known at Compilation (pre-bound) rather than at runtime (post-bound ).
[Visual Basic]
Imports System
Module Hello
Sub Main ()
'Set up variable.
Dim helloObj As Object
'Create the object.
HelloObj = new HelloWorld ()
'Invoke the print method as if it was early bound
'Even though it's really late bound.
HelloObj. PrintHello ("Visual Basic Late Bound ")
End Sub
End Module
Custom binding
In addition to being implicitly used by the compiler for binding, Reflection can also be displayed and used in the code for binding.
Common language runtime supports multiple programming languages with different binding rules. In the previous binding, the code generator can fully control the binding. However, after Reflection is used, binding must be controlled by custom binding. The Binder class provides custom control for member selection and calling.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.