Understand the CLR principle in .NET
Author: yarshray saga join (To reprint please include the author, thank you!)
* Let our language can communicate --- CLS (public language system)
1. Unified standard development:
Help create a language compatible .NET Framework, Microsoft designed a public language norm (CLS). Each language is used to run libase, and interoperability with components written in other languages, and must provide the functions described in CLS. If a language implements the required function, it is called compatible .NET. Each compatible .NET language supports the same data type, using the same .NET Framework class, compiled as the same MSIL, and use the same public language runtime management execution process. Therefore, there is no advantages and disadvantages between various compatible .NET language. Developers can freely select the best language for specific components and do not lose the ability and freedom of the platform. In addition, components written in language can be easily interoperable with components written in another language. For example, you can use C # to write a class that inherits from the base class written by Visual Basic. CLS has been submitted to ECMA to standardize, which encourages many language developers to create a contained .NET version for many languages. There are more than 20-compatible languages that are compatible with .NET in writing this article.
MSDN is a more comprehensive introduction:
MS-help: //ms.vscc/ms.msdnvs.2052/cpguide/html/cpConwhatiscommonlanguagespecification.htm
* Interaction in dynamics - Reflection (reflection)
The CLS loader manages the application domain. Such management includes loading each assembly to the corresponding application domain and controlling the memory layout of each program centralized type hierarchy.
Assembly contains modules, the module contains types, and the type is included. Reflection provides an object of package assembly, modules, and types. You can create a type of instance using a reflection, bind the type to an existing object, or get the type from an existing object. Then, you can call the type method or access its fields and properties. Reflection usually has the following uses:
Using Assembly Definitions and Load the assembly, load the modules listed in the assembly list, and find the type of the type and create an instance of this type.
Using Module Understand the following similar information: contains the assembly of the module and class in the module. You can also get all global methods or other specific non-global methods defined on the module.
Using CONSTRUctorInfo to learn the following similar information: constructor's name, parameters, access modifiers (such as public or private) and implementation of details (such as Abstract or Virtual). Use the getConstructors or getConstructor method of the Type object to call a specific constructor.
Using MethodInfo to learn about the following information: the name, return type, parameter, access modifier (such as public or private) and implementation details (such as Abstract or Virtual). Use the Type object's getMethods or getMethod method to call a specific method.
Using FieldInfo to learn about the following information: the name of the field, access the modifier (such as public or private) and implementing details (such as static); and gets or sets a field value. Use EventInfo to learn about the following similar information: the name of the event, the event handler data type, custom property, the declaration type, and the type of reflectance, etc .; and add or remove the event handler.
Use PropertyInfo to learn about the following similar information: the name of the property, the data type, the declaration type, the reflection type, and only read or can be writable, and the property value is obtained or set.
Use ParameterInfo to learn about the following information: the name of the parameter, data type, parameter is the input parameter or output parameters, and the location of the parameters in the method signature.
System.Reflection.emit Namespace class provides a special form of reflections that allow you to construct a type at runtime.
Reflection can also be used to create an application called type browser that allows users to select type and then view information about selected types.
There are other uses in the reflection. Language compilers such as JScript use reflection to construct symbol tables. System.Runtime.Serialization The class in the namespace uses the reflection to access the data and determine the field to be held. The class in the System.Runtime.Remoting namespace is indirectly used by serialization.
:
1. Starting from the Reflection API
Refer to System.Reflection Namespace
:
MS-help: //ms.vscc/ms.msdnvs.2052/cpref/html/frlrfsystemReflection.htm
2. Dynamically create Assembly
Below I am doing an example code, first of all my code and then use the dynamic view information:
Using system;
Public class sayname {
Private const string sayname = "i'm yarshray";
Public symyname () {
}
Public void outputname () {
Console.writeLine (SayName);
}
}
Using system;
Using system.reflection;
Public class yarshrayreflection {
Public static void
Main
() {
AskEMBLY AS = Assembly.Load ("SaymyName");
TYPE T = as .gettype ("SaymyName");
MethodInfo Mi = T. GetMethod ("OutputName");
Object o = activator.createInstance (T);
Mi.invoke (O);
}
}
* Belongs to our own space --- Namespace (Name Space)
1. Also talk about the namespace:
I don't want me to say more about the namespace. It is quite a folder that can contain classes. But pay attention to it, try to put the associated classes in the same name space. Because it is more convenient to maintain.
Such as:
Namespace YarshiTools
{
Using system;
Using Namespace, you can easily define the namespace, I defined a namespace named YarsHRayTools, and use the namespace that uses you can introduce the namespace.
Public Class YarshrayClass
{
This puts the class into the namespace. The method of the category in the namespace is as follows:
YarshiTools.yarshrayClass Ys = New YarsHrayTools.yarshrayClass (); You may, noticed, I am using a reference with namespace. This way is called Full Qunalfied Name, of course, if you are in your code USING YARSHRAYTOOLS
Then there is no need to do this.
appendix:
. NET Framework Tool Introduction
tool
Description
Program Cache Viewer (SHFusion.dll)
Allows the use of Windows Explorer to view and operate the global assembly cache.
Contextile (Al.exe)
Generate a file with an assembly list from one or more files (resource files, or Microsoft Intermediate Language (MSIL) files).
Contection Registration Tool (Regasm.exe)
Read metadata in the program set and add the necessary items to the registry to enable the COM client to create a .NET framework class.
Context Binding Log Viewer (FusLogvw.exe)
Details of the failed assembly binding. This information helps your diagnostics .NET framework cannot find the reason for the assembly at runtime.
Global Program Cache Tool (Gacutil.exe)
Allows viewing and operating global program set cache and download cached content. Since SHFusion.dll provides a similar function, you can use Gacutil.exe from constructive scripts, generated file files and batch files.
Installing tool (InstallUtil.exe)
Allows the server resources to be installed, and uninstalled by executing the installer components of the specified assembly.
Separate storage tool (Storeadm.exe)
List or delete all existing storage areas for users currently logged in.
Native Image Generator (NGEN.exe)
Create a native image from the managed assembly and install it in the local image cache of the local computer.
.NET Framework Configuration Tool (MSCORCFG.MSC)
Provide a graphical interface to manage .NET Framework Security Policy and an application using a remote processing service. This tool also allows you to manage and configure assemblies in the global program cache.
.NET Service Installation Tool (Regsvcs.exe)
Adding managed classes to Windows 2000 component services by loading, registering, registering, registering, and installed into existing COM 1.0 applications.
SOAPSUDS Tool (SOAPSUDS.EXE)
Use a technology called "remote processing" to help you compile client applications that communicate with XML Web Services.
Type library exporter (TLBEXP.exe)
Generate type libraries from the public language runtime assembly.
Type library import program (TLBIMP.exe)
Convert the type definition found in the COM type library into the equivalent definition of the hosted metadata format.
Web Service Description Language Tool (WSDL.exe)
From the Web Service Description Language (WSDL) protocol file, XML Architecture Definition (XSD) architecture file and .discomap discovery document generated code for XML Web Services and XML Web Services clients.
Web Service Discovery Tool (Disco.exe)
Find the URL of the XML Web Services on the web server and saved the document related to each XML Web Services to the local disk.
XML architecture definition tool (xsd.exe)
The generated XML architecture should follow the XSD language proposed by the WWW Federation (W3C). This tool generates a DataSet class that runs library classes and XSD schema files.
Debugging tool
tool
Description
Microsoft CLR Debugger (DBGCLR.exe)
Use the graphical interface to provide debugging services to help application developers find and fix errors in various programs for the running library.
Running debugger (Cordbg.exe)
Provide command line debugging services using public language runtime "debug API". Used to find and repair errors in various programs for the running library.
Recommended article reference:
http://www.zdnet.com.cn/developer/tech/story/0,2000081602,39056220-1,00.htm finally completed, I hope everyone will help. Ok, goodbye, see it next time. (Finish)