entered. In this example, you can find the System.IO.Compression namespace that contains the classes you need to use (see Figure B-7) — DeflateStream and GZipStream.

Figure B-7

Clicking on a namespace shows you which assembly contains that namespace. System.IO.Compression, for example, is contained within the System.dll assembly.

Clicking an assembly link takes you to the assembly where you can examine all the namespaces contained with it (see Figure B-8). In this example, you can see that the System assembly is a member of the three versions of the .NET Framework — 2.0, 3.0, and 3.5. That's a useful feature because if you use an assembly that belongs only to .NET Framework 3.5, for instance, then you need to ensure that the computer running your application has the latest version of the Framework.

Figure B-8

Once you have selected an assembly, you can also click the Add to Reference button (see Figure B-9) in the Object Browser to add a reference to the assembly.

Figure B-9

Appendix C

Generating Documentation for Your C# Applications

Documenting your code is probably the last thing you would do in your typical project cycle. While the importance of writing documentation has been stressed umpteen times, developers usually devote the best part of the project cycle to building new features, and then finally do a mediocre job at the end writing the dreaded documentation. Borrowing the popular 'clean as you go' phrase found in a lot of kitchens, the best way to churn out top-quality documentation for your project is to document as you go.

In Visual Studio 2008, you can document your code using the XML code documentation feature. This appendix shows you how to generate MSDN-style documentation for your project using Visual Studio 2008 and a third-party documentation generation tool — Sandcastle.

Inline Documentation using XML

To see how XML documentation works, create a new class library project in Visual Studio 2008 as shown in Figure C-1. Name the project PointClass.

Figure C-1

Populate the default Class1.cs with the following class definition:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace PointClass {

 public class Point {

  //---static variable---

  private static int count;

  //---properties---

  public int x { get; set; }

  public int y { get; set; }

  //---constructors---

  public Point() {

   count++;

  }

  public Point(int x, int y) {

   this.x = x;

   this.y = y;

   count++;

  }

  //---overloaded methods---

  public double Length() {

   return Math.Sqrt(

    Math.Pow(this.x, 2) +

    Math.Pow(this.y, 2));

  }

  public double Length(Point pt) {

   return Math.Sqrt(

    Math.Pow(this.x - pt.x, 2) +

    Math.Pow(this.y - pt.y, 2));

  }

 }

}

The definition for the Point class contains the following members:

□ A static private member named count

□ Two properties — x and y

□ Two overloaded constructors

□ Two overloaded Length() methods

To add XML comments to the class, type three slash (/) character in succession: ///. Figure C-2 shows that when you type /// before the Point class definition, an XML comments template is automatically inserted for you.

Figure C-2

The <summary> tag is inserted by default, but you can insert additional XML comment tags within the XML comments template, as shown in Figure C-3.

Figure C-3

Following is a list of XML documentation tags. You can find a similar list with a link to each tag's description (its uses) at http://msdn.microsoft.com/en-us/library/5ast78ax.aspx.

<c>             <para>       <see>

<code>          <param>      <seealso>

<example>       <paramref>   <summary>

<exception>     <permission> <typeparam>

<typeparamrefs> <value>      <include>

Вы читаете C# 2008 Programmer's Reference
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату