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

发布于 2024-11-24 03:55:58 字数 238 浏览 2 评论 0原文

顾名思义,我不知道如何引用字典索引器。这里有什么帮助吗? :)

仅供参考,我已经尝试过:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

早茶月光 2024-12-01 03:55:58

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

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 { }
        }
    }
}

您可以通过检查生成的 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>

注意第一个 P: 如何与第二个匹配。

最后,确保它可以与 Intellisense 配合使用:

Intellisense for Indexer


原始海报更新 (myermian):

我做了一点挖掘并发现索引器属性的缩写形式只是“this”。例如:<参见 cref="this"/>

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

万劫不复 2024-12-01 03:55:58

尝试 (名称是 Item,而不是 Items)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文