Today's main discussionProgramMethods for dataset and reflection
Assembly:
The Assembly element Board includes the Win32 file header, the CLR file header, and the Assembly List.
Win32 File Header
01. enable the Assembly to be loaded and operated by the Windows operating system
02. identify the type of the application in the Windows operating system (console, Gui or web page)
03. Use dumpbin.exe and/headers to mark the Win32 file header information of the Assembly.
Example: dumpbin test.exe/Headers
CLR File Header
It defines multiple tags so that the runtime can understand the layout of hosted files.
Use the dumpin.exe tool and/clrheader to mark the CLR header information inside the assembly.
Assembly List
A list is used to describe the relationship between elements in a set and the metadata of the other Assembly that the Assembly depends on when it is working normally.
CelCode
In running, the template code inside the assembly is compiled as the platform and CPU commands.
Type metadata:
Complete description of the format of the Assembly containing type and reference external type
Assembly resources
The. NET Assembly specified by Assembly resources can contain embedded resources, tables, images, and sounds.
The Assembly can be a DLL file or an EXE file.
Build and use an assembly
Case: Build an assembly and use it
01. Create a ctop class library project that contains the strtopinyin class. The class has a getchinesespell method. The method prototype is as follows:
02. Create a winform application librarytest to reference this assembly.
Reference procedure: Right-click to add a reference
Then introduce the corresponding Assembly through using ctop.
03. Write the following code in the txtchinese keyup event
In this way, we can call methods in a centralized program.
Decompilation to view program information
Meanings of common tags:
Shared assembly
Shared assembly is a combination of types and resources. If we need a machine-level class library, we should deploy it as a shared assembly. Before deploying a shared assembly to GAC, you must give it a strong name.
Strong name:
A strong name is composed of the Assembly identifier plus the public key and digital signature. The Assembly identifier includes the simple text name, version number, and regional information (if provided ). It uses the corresponding private key to generate from the Assembly file. (The Assembly file contains the Assembly List, including the names and hashing of all the files that make up the Assembly .)
An assembly with strong names can only use other types of assembly with strong names. Otherwise, the security of the Assembly with a strong name will be compromised.
Set a strong name for the Assembly:
Reflection definition:
Reflection (reflection) is. net, which can be obtained at runtime through radiation. net, including methods, attributes, events, and constructor. You can also obtain the name, qualifier, and parameters of each member. With reflection, you can be familiar with every type. If you obtain information about the constructor, you can directly create an object, even if the object type is unknown during compilation.
Reflection mechanism
Use the Assembly class to obtain all modules in the Assembly, obtain the types in the corresponding module, and then obtain the corresponding methods, attributes, and events in the type. The Code is as follows:
Assembly = assembly. loadfrom (@ "F: \ ASP. NET learning start \ multithreading \ CSHARP basics \ ctop \ bin \ debug \ ctop. dll ");
Module [] modules = assembly. getmodules ();
Foreach (module in modules)
{
Type [] types = module. gettypes ();
Foreach (type in types)
{
Console. writeline (type. Name );
// Reflect all methods of the corresponding type
Methodinfo [] methodinfos = type. getmethods ();
Foreach (methodinfo in methodinfos)
{
Console. writeline (methodinfo. Name );
}
Console. writeline ("method ================== ");
}
Console. writeline ("============== ");
}
Console. readkey ();
Now, let's introduce the Assembly and reflection content here.