1.4.1 private assembly
Private assemblies are the simplest types in the program. They came with the software in the software and were only used by the software. Under normal circumstances, this is the case. You are writing a application consisting of a user and several class libraries, and the code in the class library You just want this application to use.
The system guarantees that the private assembly will not be used by other software, as the application can only load the private assembly with the primary executable in the same directory or its subdirectories.
Since we generally believe that commercial software will always be installed in his own directory, this is to say that there is no package that has been overwritten, modified or applied to other packages other than the application outside of the package. Therefore, the assembly can only be used by the package you have, so you have more control rights for what software. Therefore, there is no need to take safety precautions, and there will be no other commercial software to override your assembly with some new versions (except for software designed to perform malicious damage). Of course, there is no conflict in the name. If your private assembly class and other people's private assembly is not tight, because any application can only use its own private assembly.
Because a private assembly is completely included, it is very simple to configure their process. In deployment, you only need to simply simply enter the specific directory of the application file directory system (no registration registration item). This process is called "zero impact installation" (or Xcopy installation, or we say green installation).
1.4.2 Sharing assembly
Sharing assemblies are specified as a public library that can be used by any application. Because any software can access the shared assembly. It is necessary to take some protection measures to avoid the following risks:
❑ Name conflict, other company sharing assemblies have the same name and your own shared assembly has the same name. This is a serious problem because the client code has theoretically access two assemblies at the same time.
❑ There is a possibility that a program that has a basic version of the same assembly of different versions, and the new version may not be compatible with some already existing client code.
The solution to these issues is to place the shared assembly in a specific catalog sub-tree in the file system, known as Global Assembly Cache (GAC). Unlike private assemblies, it is not possible to copy the shared assembly to the application's directory, which needs to be dedicated to the buffer. This process can be done with many .NET tools, including specific inspections for assemblies, including a small directory hierarchy in the assembly buffer to ensure assembly integrity.
In order to eliminate the possibility of the name conflict, the shared assembly does not give a name based on private key encryption method (private assembly only needs to specify the name of its primary file as its name). This name is called "strong name" to ensure unique, and each reference to the shared assembly must provide this name.
The problem that the assembly may be overwritten by allowing the same assembly that allows both different versions of the two versions to solve it in the assembly list,
1.4.3 reflection
Because the program is stored in metadata, including all the types of all types and these types of members are defined in the assembly, so they can access metadata. All of this will be discussed in Chapter 10. This is a technique that is likely to be reflected, indicating that the hosted code can detect other managed code even detect itself, the information that has been determined. Reflection is often used to obtain details of the attribute, of course, you can also use reflection techniques for other purposes, such as by indirectly implementing classes or calling methods by providing the names of the class or method in a string. Through this method you can decide to installize the class or the method you need to call at runtime, without the need to be determined before the program is compiled.
1.5 .NET Framework class library
At least from one developer's point of view, a biggest advantage of writing hosting code is that you can use the .NET Basic Library. The .NET basic class is a collection of a lot of hosted codes that have been prepared, almost all work that can be done with Windows APIs can be done. These classes also follow the object models used in IL, based on single-successive object model. This is to say that you can instantiate any .NET basic class, or you can derive your own class from it.
A huge advantage of .NET basic class library is to use it very convenient. For example, if you want to start a thread, you can call the Start () method of the Thread class directly. If you want to destroy a TextBox, you need to design the enabled property of the TextBox object to false. Although Visual Basic and Java developers are familiar with this convenient class library, this has brought great relief for C developers. After all, they have been using getDibits (), registerWndClassex () And the API function such as ISEquali ID, and there is a lot of Windows Handles to be delivered.
On the other hand, C developers can always easily access the entire Windows API, and Visual Basic 6 and Java developers will receive a lot of restrictions through the basic functions of accessing the operating system through their own language. The innovation of the .NET basic class library is that it combines the convenience of the Visual Basic and Java class libraries and overwrites the entire Windows API feature. Of course, there are still some Windows features that we cannot get through the use of the basic class library, you must use the API function to be implemented, however, those who are not available are some special features. For daily applications, the base class library is already enough. If you really need to call the API function, no matter if you are using C #, C , or Visual Basic .NET, .NET also provides so-called "Platform- Invoke" to ensure that the data type is converted correctly, so this call There is no difficulty in calling the function directly in C .
Note: WinCV, a Windows utility that can be used to explore class, structures, interfaces, and enumeration types in the underlying class library. We will discuss WinCV in Chapter 12.
Although the third chapter is used in the topic, it is used to introduce the theme of the basic class library, but in fact, when we complete the syntax of the C # language, the main task of this book is to teach you how to use .NET basic class A variety of classes in the library. This is a very broad basic class library! As a rough introduction, .NET's basic class library includes:
❑ IL provides the core characteristics (including, basic data types and CTS, see Chapter 3)
❑ WINDOWS GUI support and control (see Chapter 19)
❑ Web Forms (ASP.NET, discussed in Chapter 25 and 2)
❑ Data Access (ADO.NET, Chapter 21 and 22)
❑ Directory Access (see Chapter 24)
❑ File system and registry access (see Chapter 30)
❑ Network and web tour (see Chapter 31)
❑ .net attributes and reflections (see Chapter 10)
❑ Access Windows operating system (environment variables, see Chapter 14)
❑ COM interoperability (see chapter 28 and 29)
With an instructions, most of the code in the .NET underlying library is actually written in C # according to Microsoft's source files! 1.5.1 namespace
Namespace is a way to conflict between .NET cancellation classes and classes. He is used to avoid the following: You define a class that represents a consumer, and gives her a name called Customer, and there is another person to do this, which causes a conflict (imagine, there are many Consumers' business).
The namespace is just a set of data types, but the data type in the namespace automatically adds the namespace name before the name. And the namespace can be nested to each other. For example, most .NET base classes for general purpose are placed in a namespace called System. Basic class Array is in this namespace, so the full name of the array is System.Array.
.NET requires all data types to be defined in the namespace, for example, you can put your Customer class in a namespace called YourCompanyName. This is the full name of this class is "YourCompanyName.customer".
Note: If no namespace clearly provides, the defined type will be added to a global namespace without a name.
Microsoft suggests that for most situations, you should specify a namespace name of at least two nesting structures: The first referring to your company name, the second use to refer to the name of the technology or package existing For example, YourCompanyName.salesservices.customer. This ensures that the class of your application will not be named in most situations.
We will learn more about the namespace in more detail on Chapter 2.
1.6 Create a .NET application with C #
C # Of course, can be used to create a console application, a application that has only text running under the DOS window. You may use the console application when you test the class library, or use it when you create a UNIX or Linux daemon process. However, in more case you will create some applications that use more .NET technology with C #. In this section, we will take a general understanding of the C # which different types of applications can be created.
1.6.1 Creating an ASP.NET application
Active Server Pages (ASP) is Microsoft used to create a Web with dynamic content. An ASP page is basically a file that adds a large block running on the server-side VBScript or JavaScript code in HTML. When a client beacker requests an ASP page, the web server handles the server-side code and sends together with the HTML section to the client. Typically, these scripts are queried from the database and marked these data with HTML. For customers, ASP is an easy way to create an audio-based application.
However, ASP does not have no shortcomings. First, the ASP page is slower because the server-side code is interpreted, not compiled. Second, the ASP file is difficult to maintain because they are unable structure, the server-side ASP code is completely mixed with ordinary HTML code. Third, sometimes developing ASP is also difficult because ASP supports rare to error handling and type checks.
Special, if you want to use VBScript to implement an error with VBScript in your page, you must use the ON Error Resume next to declare, and check Check Err.Number to determine whether the call to each component is normal.
ASP.NET is a new version of ASP and amended many questions. ASP.NET is not to replace the ASP. Instead, the ASP.NET page can exist on the same server with the original ASP application. Of course, you can write ASP.NET applications with C #.
We will explore the key features of ASP.NET. If you want to get more details, please refer to Chapter 25 to 27.