다음을 통해 공유


방법: XML 문서 기능 사용(C# 프로그래밍 가이드)

다음 예제에서는 문서화 된 형식에 기본 개요를 제공 합니다.

예제

// If compiling from the command line, compile with: /doc:YourFileName.xml 

/// <summary> 
/// Class level summary documentation goes here.</summary> 
/// <remarks> 
/// Longer comments can be associated with a type or member through 
/// the remarks tag.</remarks> 
public class TestClass : TestInterface
{
    /// <summary> 
    /// Store for the name property.</summary> 
    private string _name = null;

    /// <summary> 
    /// The class constructor. </summary> 
    public TestClass()
    {
        // TODO: Add Constructor Logic here.
    }

    /// <summary> 
    /// Name property. </summary> 
    /// <value> 
    /// A value tag is used to describe the property value.</value> 
    public string Name
    {
        get
        {
            if (_name == null)
            {
                throw new System.Exception("Name is null");
            }
            return _name;
        }
    }

    /// <summary> 
    /// Description for SomeMethod.</summary> 
    /// <param name="s"> Parameter description for s goes here.</param>
    /// <seealso cref="System.String">
    /// You can use the cref attribute on any tag to reference a type or member  
    /// and the compiler will check that the reference exists. </seealso> 
    public void SomeMethod(string s)
    {
    }

    /// <summary> 
    /// Some other method. </summary> 
    /// <returns> 
    /// Return results are described through the returns tag.</returns> 
    /// <seealso cref="SomeMethod(string)">
    /// Notice the use of the cref attribute to reference a specific method. </seealso> 
    public int SomeOtherMethod()
    {
        return 0;
    }

    public int InterfaceMethod(int n)
    {
        return n * n;
    }

    /// <summary> 
    /// The entry point for the application. 
    /// </summary> 
    /// <param name="args"> A list of command line arguments.</param>
    static int Main(System.String[] args)
    {
        // TODO: Add code to start application here. 
        return 0;
    }
}

/// <summary> 
/// Documentation that describes the interface goes here. 
/// </summary> 
/// <remarks> 
/// Details about the interface go here. 
/// </remarks> 
interface TestInterface
{
    /// <summary> 
    /// Documentation that describes the method goes here. 
    /// </summary> 
    /// <param name="n">
    /// Parameter n requires an integer argument. 
    /// </param> 
    /// <returns> 
    /// The method returns an integer. 
    /// </returns> 
    int InterfaceMethod(int n);
}
                

코드 컴파일

예제를 컴파일하려면 다음 명령줄을 입력 합니다.

csc XMLsample.cs /doc:XMLsample.xml

브라우저에서 또는 TYPE 명령을 사용 하 여 볼 수 있습니다 Xmlsample.xml을 XML 파일을 만듭니다.

강력한 프로그래밍

XML 문서는 ///로 시작합니다. 새 프로젝트를 만들 때 마법사에서 일부 기초 / / / 줄을 배치 합니다. 이러한 주석 처리에는 몇 가지 제한이 있습니다.

  • 이 문서는 반드시 제대로 구성된 XML이어야 합니다. XML을 제대로 구성 하지 않으면 경고가 생성 되 고 설명서 파일에 오류가 발생 했음을 알리는 주석을 포함 됩니다.

  • 개발자는 자유롭게 자체 태그 집합을 만들 수 있습니다. 권장된 (추가 정보 단원을 참조) 태그 집합이입니다. 권장 태그 중에는 특별한 의미가 있는 것도 있습니다.

    • <param> 태그는 매개 변수를 설명하는 데 사용됩니다. 이 태그를 사용하면 컴파일러가 매개 변수의 존재를 확인하며 모든 매개 변수가 문서에서 설명됩니다. 유효성 검증에 실패 한 경우에 컴파일러에서 경고가 발생 합니다.

    • cref 특성은 모든 태그에 연결되어 코드 요소에 대한 참조를 제공할 수 있습니다. 컴파일러는이 코드 요소가 존재 하는지 확인 합니다. 유효성 검증에 실패 한 경우에 컴파일러에서 경고가 발생 합니다. 컴파일러는 cref 특성에 설명된 형식을 찾을 때 모든 using 문을 고려합니다.

    • <summary> 태그는 Visual Studio 내의 IntelliSense에 의해 사용되어 형식이나 멤버에 관한 추가 정보를 표시합니다.

      참고

      XML 파일은 형식과 멤버에 대 한 전체 정보를 제공 하지 않습니다 (예를 들어, 형식 정보가 포함 되지 않습니다).형식이나 멤버에 대한 전체 정보를 보려면 실제 형식이나 멤버에 반영한 문서 파일을 사용해야 합니다.

참고 항목

참조

/doc(C# 컴파일러 옵션)

XML 문서 주석(C# 프로그래밍 가이드)

개념

C# 프로그래밍 가이드