6

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]"/>
myermian
  • 31,823
  • 24
  • 123
  • 215

2 Answers2

7

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"/>

myermian
  • 31,823
  • 24
  • 123
  • 215
Rick Sladkey
  • 33,988
  • 6
  • 71
  • 95
  • Any way you could tell me what the shorthanded version of that is? The rest of my code all uses the shorthand version, so this long long value sticks out like a sore thumb. – myermian Jul 15 '11 at 11:15
  • Empirically, I could not find a short form for this indexer that resolves correctly. The long form allows you to specify arbitrary members. If there were a short form that resolves, I agree it would be more elegant and convenient. – Rick Sladkey Jul 15 '11 at 17:21
  • Well, I'm sure there is (everything has a short form). It's just trying to figure out what it is. Usually, it's easy. But, this indexer has given me pains, oh the pains. – myermian Jul 15 '11 at 19:53
  • Please update the answer to include that the shortform is ``. Yep, just a *this* will expand out properly. Took awhile to discover the short form. Seems so logical and simple now. :) – myermian Jul 25 '11 at 20:59
4

Try <see cref="P:Item(System.Int32)" /> (the name is Item, not Items)

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171