Поделиться через


Processing the XML File (C# Programming Guide)

The compiler generates an ID string for each construct in your code that is tagged to generate documentation. (For information about how to tag your code, see Recommended Tags for Documentation Comments.) The ID string uniquely identifies the construct. Programs that process the XML file can use the ID string to identify the corresponding .NET Framework metadata/reflection item that the documentation applies to.

The XML file is not a hierarchical representation of your code; it is a flat list that has a generated ID for each element.

The compiler observes the following rules when it generates the ID strings:

  • No whitespace is in the string.

  • The first part of the ID string identifies the kind of member being identified, by way of a single character followed by a colon. The following member types are used:

    Character

    Description

    N

    namespace

    You cannot add documentation comments to a namespace, but you can make cref references to them, where supported.

    T

    type: class, interface, struct, enum, delegate

    F

    field

    P

    property (including indexers or other indexed properties)

    M

    method (including such special methods as constructors, operators, and so forth)

    E

    event

    !

    error string

    The rest of the string provides information about the error. The C# compiler generates error information for links that cannot be resolved.

  • The second part of the string is the fully qualified name of the item, starting at the root of the namespace. The name of the item, its enclosing type(s), and namespace are separated by periods. If the name of the item itself has periods, they are replaced by the hash-sign ('#'). It is assumed that no item has a hash-sign directly in its name. For example, the fully qualified name of the String constructor would be "System.String.#ctor".

  • For properties and methods, if there are arguments to the method, the argument list enclosed in parentheses follows. If there are no arguments, no parentheses are present. The arguments are separated by commas. The encoding of each argument follows directly how it is encoded in a .NET Framework signature:

    • Base types. Regular types (ELEMENT_TYPE_CLASS or ELEMENT_TYPE_VALUETYPE) are represented as the fully qualified name of the type.

    • Intrinsic types (for example, ELEMENT_TYPE_I4, ELEMENT_TYPE_OBJECT, ELEMENT_TYPE_STRING, ELEMENT_TYPE_TYPEDBYREF. and ELEMENT_TYPE_VOID) are represented as the fully qualified name of the corresponding full type. For example, System.Int32 or System.TypedReference.

    • ELEMENT_TYPE_PTR is represented as a '*' following the modified type.

    • ELEMENT_TYPE_BYREF is represented as a '@' following the modified type.

    • ELEMENT_TYPE_PINNED is represented as a '^' following the modified type. The C# compiler never generates this.

    • ELEMENT_TYPE_CMOD_REQ is represented as a '|' and the fully qualified name of the modifier class, following the modified type. The C# compiler never generates this.

    • ELEMENT_TYPE_CMOD_OPT is represented as a '!' and the fully qualified name of the modifier class, following the modified type.

    • ELEMENT_TYPE_SZARRAY is represented as "[]" following the element type of the array.

    • ELEMENT_TYPE_GENERICARRAY is represented as "[?]" following the element type of the array. The C# compiler never generates this.

    • ELEMENT_TYPE_ARRAY is represented as [lowerbound:size,lowerbound:size] where the number of commas is the rank - 1, and the lower bounds and size of each dimension, if known, are represented in decimal. If a lower bound or size is not specified, it is simply omitted. If the lower bound and size for a particular dimension are omitted, the ':' is omitted as well. For example, a 2-dimensional array with 1 as the lower bounds and unspecified sizes is [1:,1:].

    • ELEMENT_TYPE_FNPTR is represented as "=FUNC:type(signature)", where type is the return type, and signature is the arguments of the method. If there are no arguments, the parentheses are omitted. The C# compiler never generates this.

    The following signature components are not represented because they are never used for differentiating overloaded methods:

    • calling convention

    • return type

    • ELEMENT_TYPE_SENTINEL

  • For conversion operators only (op_Implicit and op_Explicit), the return value of the method is encoded as a '~' followed by the return type, as encoded above.

  • For generic types, the name of the type will be followed by a back tick and then a number that indicates the number of generic type parameters. For example,

    <member name="T:SampleClass`2"> is the tag for a type that is defined as public class SampleClass<T, U>.

    For methods taking generic types as parameters, the generic type parameters are specified as numbers prefaced with back ticks (for example `0,`1). Each number representing a zero-based array notation for the type's generic parameters.

Examples

The following examples show how the ID strings for a class and its members would be generated:

namespace N
{
    /// <summary> 
    /// Enter description here for class X.  
    /// ID string generated is "T:N.X". 
    /// </summary> 
    public unsafe class X
    {
        /// <summary> 
        /// Enter description here for the first constructor. 
        /// ID string generated is "M:N.X.#ctor".
        /// </summary> 
        public X() { }


        /// <summary> 
        /// Enter description here for the second constructor. 
        /// ID string generated is "M:N.X.#ctor(System.Int32)".
        /// </summary> 
        /// <param name="i">Describe parameter.</param>
        public X(int i) { }


        /// <summary> 
        /// Enter description here for field q. 
        /// ID string generated is "F:N.X.q".
        /// </summary> 
        public string q;


        /// <summary> 
        /// Enter description for constant PI. 
        /// ID string generated is "F:N.X.PI".
        /// </summary> 
        public const double PI = 3.14;


        /// <summary> 
        /// Enter description for method f. 
        /// ID string generated is "M:N.X.f".
        /// </summary> 
        /// <returns>Describe return value.</returns> 
        public int f() { return 1; }


        /// <summary> 
        /// Enter description for method bb. 
        /// ID string generated is "M:N.X.bb(System.String,System.Int32@,System.Void*)".
        /// </summary> 
        /// <param name="s">Describe parameter.</param>
        /// <param name="y">Describe parameter.</param>
        /// <param name="z">Describe parameter.</param>
        /// <returns>Describe return value.</returns> 
        public int bb(string s, ref int y, void* z) { return 1; }


        /// <summary> 
        /// Enter description for method gg. 
        /// ID string generated is "M:N.X.gg(System.Int16[],System.Int32[0:,0:])". 
        /// </summary> 
        /// <param name="array1">Describe parameter.</param>
        /// <param name="array">Describe parameter.</param>
        /// <returns>Describe return value.</returns> 
        public int gg(short[] array1, int[,] array) { return 0; }


        /// <summary> 
        /// Enter description for operator. 
        /// ID string generated is "M:N.X.op_Addition(N.X,N.X)". 
        /// </summary> 
        /// <param name="x">Describe parameter.</param>
        /// <param name="xx">Describe parameter.</param>
        /// <returns>Describe return value.</returns> 
        public static X operator +(X x, X xx) { return x; }


        /// <summary> 
        /// Enter description for property. 
        /// ID string generated is "P:N.X.prop".
        /// </summary> 
        public int prop { get { return 1; } set { } }


        /// <summary> 
        /// Enter description for event. 
        /// ID string generated is "E:N.X.d".
        /// </summary> 
        public event D d;


        /// <summary> 
        /// Enter description for property. 
        /// ID string generated is "P:N.X.Item(System.String)".
        /// </summary> 
        /// <param name="s">Describe parameter.</param>
        /// <returns></returns> 
        public int this[string s] { get { return 1; } }


        /// <summary> 
        /// Enter description for class Nested. 
        /// ID string generated is "T:N.X.Nested".
        /// </summary> 
        public class Nested { }


        /// <summary> 
        /// Enter description for delegate. 
        /// ID string generated is "T:N.X.D". 
        /// </summary> 
        /// <param name="i">Describe parameter.</param>
        public delegate void D(int i);


        /// <summary> 
        /// Enter description for operator. 
        /// ID string generated is "M:N.X.op_Explicit(N.X)~System.Int32".
        /// </summary> 
        /// <param name="x">Describe parameter.</param>
        /// <returns>Describe return value.</returns> 
        public static explicit operator int(X x) { return 1; }

    }
}

See Also

Reference

/doc (C# Compiler Options)

XML Documentation Comments (C# Programming Guide)

Concepts

C# Programming Guide