Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML Comments - How do you reference a dictionary indexer properly?

As the name states, I have no idea how to reference a dictionary indexer. Any help here? :)

FYI, I've tried:

<see cref="Item"/>
<see cref="Item(Int32)"/> //Highly doubted this would work.
<see cref="Item(TKey)"/>
<see cref="Item[TKey]"/>
like image 637
myermian Avatar asked Jul 15 '11 02:07

myermian


People also ask

What are XML comments in C#?

C# documentation comments use XML elements to define the structure of the output documentation. One consequence of this feature is that you can add any valid XML in your documentation comments. The C# compiler copies these elements into the output XML file.

What sequence of characters indicates the start of an XML style documentation comment in C# code?

The use of XML doc comments requires delimiters that indicate where a documentation comment begins and ends. You use the following delimiters with the XML documentation tags: /// Single-line delimiter: The documentation examples and C# project templates use this form.

How do you write a summary comment in C#?

The first rule for commenting is it should have /// three slash for comments as C# supports C++ style commenting so commenting can be done by // -- two slashes -- but for Documentation /// is necessary. We will go through each one by one. You can add a paragraph to the description by using <para> tag.


1 Answers

You can use the full property syntax to reference indexers:

namespace ConsoleApplication1
{
    /// <summary>
    /// See indexer <see cref="P:ConsoleApplication1.MyDictionary`2.Item(`0)"/>
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <typeparam name="TValue"></typeparam>
    public class MyDictionary<TKey, TValue>
    {
        /// <summary>
        /// Indexer
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public TValue this[TKey key]
        {
            get { return default(TValue); }
            set { }
        }
    }
}

You can check that the property was resolved properly by inspecting the generated XML file:

<doc>
    <assembly>
        <name>ConsoleApplication1</name>
    </assembly>
    <members>
        <member name="T:ConsoleApplication1.MyDictionary`2">
            <summary>
            See <see cref="P:ConsoleApplication1.MyDictionary`2.Item(`0)"/>
            </summary>
            <typeparam name="TKey"></typeparam>
            <typeparam name="TValue"></typeparam>
        </member>
        <member name="P:ConsoleApplication1.MyDictionary`2.Item(`0)">
            <summary>
            Indexer
            </summary>
            <param name="key"></param>
            <returns></returns>
        </member>
    </members>
</doc>

Notice how the first P: matches the second one.

Finally, make sure it's working with Intellisense:

Intellisense for Indexer


Update by Original Poster (myermian):

I did a little bit of digging and have discovered that the shortform of an indexer property is just "this". Ex: <see cref="this"/>

like image 168
Rick Sladkey Avatar answered Sep 20 '22 17:09

Rick Sladkey