Wei-Meng Lee - C# 2008 Programmer's Reference

Здесь есть возможность читать онлайн «Wei-Meng Lee - C# 2008 Programmer's Reference» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2009, ISBN: 2009, Издательство: Wiley Publishing, Inc., Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

C# 2008 Programmer's Reference: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «C# 2008 Programmer's Reference»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

C# 2008 Programmers Reference provides a concise and thorough reference on all aspects of the language. Each chapter contains detailed code samples that provide a quick and easy way to understand the key concepts covered.

C# 2008 Programmer's Reference — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «C# 2008 Programmer's Reference», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

gacutil /i Base64Codec.dll

Figure 1535 If you are using Windows Vista make sure to run the command - фото 245

Figure 15-35

If you are using Windows Vista, make sure to run the command prompt as Administrator.

If the installation is successful, you will see the shared assembly in the Assembly Cache Viewer (see Figure 15-36).

Figure 1536 The version number displayed next to the DLL is specified by - фото 246

Figure 15-36

The version number displayed next to the DLL is specified by using the AssemblyVersionattribute in the AssemblyInfo.csfile (as discussed earlier). Select the Base64Codec DLL, and click the Properties button (the button with the tick icon) to see the Properties page as shown in Figure 15-37.

Figure 1537 The version number displayed in this page is specified using the - фото 247

Figure 15-37

The version number displayed in this page is specified using the AssemblyFileVersionattribute.

To install different versions of the same assembly to the GAC, simply modify the version number in AssemblyInfo.cs(via the AssemblyVersionattribute), recompile the assembly, and install it into the GAC.

Physically, the shared assembly is copied to a folder located under the GAC_MSILsubfolder of the GAC, in the following format:

\assembly\GAC_MSIL\\_

In this example, it is located in:

C:\Windows\assembly\GAC_MSIL\Base64Codec\1.0.0.0_2a7dec4fb0bb6

Figure 15-38 shows the physical location of the Base64Codec.dllassembly.

Figure 1538 Making the Shared Assembly Visible in Visual Studio By - фото 248

Figure 15-38

Making the Shared Assembly Visible in Visual Studio

By default, adding a shared assembly into the GAC does not make it appear automatically in Visual Studio's Add Reference dialog. You need to add a registry key for that to happen. Here's how to handle that.

First, launch the registry editor by typing regeditin the Run command box.

If you are using Windows Vista, make sure to run regedit as Administrator.

Navigate to the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolderskey. Right-click on the AssemblyFolders key and select New→Key (see Figure 15-39).

Figure 1539 Name the new key Base64Codec Doubleclick on the keys - фото 249

Figure 15-39

Name the new key Base64Codec. Double-click on the key's (Default) value, and enter the full path of the shared assembly (for example, C:\Documents and Settings\Wei-Meng Lee\My Documents\Visual Studio 2008\Projects\Base64Codec\bin\Debug; see Figure 15-40).

Figure 1540 Then restart Visual Studio 2008 and the assembly should appear - фото 250

Figure 15-40

Then restart Visual Studio 2008, and the assembly should appear in the Add Reference dialog.

Using the Shared Assembly

Let's now create a new Windows application project to use the shared assembly stored in the GAC. Name the project WinBase64.

To use the shared assembly, add a reference to the DLL. In the Add Reference dialog, select the Base64Codecassembly, as shown in Figure 15-41, and click OK.

Figure 1541 Note in the Properties window that the Copy Local property of - фото 251

Figure 15-41

Note in the Properties window that the Copy Local property of the Base64Codec is set to False (see Figure 15-42), indicating that the assembly is in the GAC.

Figure 1542 Populate the default Form1with the controls shown in Figure - фото 252

Figure 15-42

Populate the default Form1with the controls shown in Figure 15-43 (load the pictureBox1with a JPG image).

Figure 1543 In the codebehind of Form1 define the two helper functions as - фото 253

Figure 15-43

In the code-behind of Form1, define the two helper functions as follows:

Remember to import the System.IOnamespace for these two helper functions.

public byte[] ImageToByteArray(Image img) {

MemoryStream ms = new MemoryStream();

img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);

return ms.ToArray();

}

public Image ByteArrayToImage(byte[] data) {

MemoryStream ms = new MemoryStream(data);

Image img = new Bitmap(ms);

return img;

}

Code the Test button as follows:

private void btnTest_Click(object sender, EventArgs e) {

//---create an instance of the Helper class---

Base64Codec.Helper codec = new Base64Codec.Helper();

//---convert the image in pictureBox1 to base64---

string base64string =

codec.Encode(ImageToByteArray(pictureBox1.Image));

//---decode the base64 to binary and display in pictureBox2---

pictureBox2.Image = ByteArrayToImage(codec.Decode(base64string));

}

Here you are creating an instance of the Helperclass defined in the shared assembly. To test that the methods defined in the Helperclass are working correctly, encode the image displayed in pictureBox1to base64, decode it back to binary, and then display the image in pictureBox2.

Press F5 to test the application. When you click the Test button, an identical image should appear on the right (see Figure 15-44).

Figure 1544 Examine the manifest of the WinBase64exeassembly to see the - фото 254

Figure 15-44

Examine the manifest of the WinBase64.exeassembly to see the reference to the Base64Codec assembly (see Figure 15-45). Observe the public key token stored in the manifest — it is the public key token of the shared assembly.

Figure 1545 Summary This chapter explained the parts that make up a NET - фото 255

Figure 15-45

Summary

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «C# 2008 Programmer's Reference»

Представляем Вашему вниманию похожие книги на «C# 2008 Programmer's Reference» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «C# 2008 Programmer's Reference»

Обсуждение, отзывы о книге «C# 2008 Programmer's Reference» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x