XML注释 - 如何正确引用字典索引器?

m-y*_*m-y 6 c# dictionary indexer xml-comments

正如名称所述,我不知道如何引用字典索引器.这里有什么帮助?:)

仅供参考,我尝试过:

<see cref="Item"/>
<see cref="Item(Int32)"/> //Highly doubted this would work.
<see cref="Item(TKey)"/>
<see cref="Item[TKey]"/>
Run Code Online (Sandbox Code Playgroud)

Ric*_*key 7

您可以使用完整属性语法来引用索引器:

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 { }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

您可以通过检查生成的XML文件来检查属性是否已正确解析:

<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>
Run Code Online (Sandbox Code Playgroud)

注意第一个P:匹配第二个.

最后,确保它与Intellisense一起使用:

索引器的智能感知


原始海报更新(myermian):

我做了一些挖掘,并发现索引器属性的缩写只是" 这个 ".例如:<see cref="this"/>