如何在C#注释中引用类的索引器成员

时间:2022-09-01 23:51:07

In order to reference a member of a class in XML comments/documentation, you have to use the following tag:

要在XML注释/文档中引用类的成员,您必须使用以下标记:

<see cref="member"/>

It is better explained here.

这里有更好的解释。

How do you reference an indexer?

你如何引用索引器?

I mean, a member like this one:

我的意思是,像这样的成员:

internal object this[ int index ] {
    ...
}

Thanks in advance.

提前致谢。

5 个解决方案

#1


11  

<see cref="P:System.Collections.ArrayList.Item(System.Int32)" />

#2


5  

<see cref="this[int]" />

#3


1  

In general, in order to find out, how to reference any member in your comments, find the member in your XML documentation file for the assembly. It is created on each build. With the only exception of generics the member reference can be taken from here:

通常,为了找出如何引用注释中的任何成员,请在XML文档文件中找到该程序集的成员。它是在每个构建上创建的。除了泛型之外,成员参考可以从这里获取:

</member>
<member name="P:My.Namespace.Class1.Item(System.String)">
    <summary>
       retrieve a single item of the given name from this instance
    </summary>
    <param name="name">name of the item</param>
    <returns>the item</returns>
</member>
<member name="M:My.Namespace.Class1.Function1(System.Int32[])">
    <summary> 
    ... 

Unfortunately, generic definition formats seem not to be compatible between the documentation file and the cref tags. While in the XML file, generics look like that:

不幸的是,通用定义格式似乎在文档文件和cref标签之间不兼容。在XML文件中,泛型看起来像这样:

<member name="M:My.Namespace.Class1.Get``1(System.String)">
    <summary>
    retrieve an named item of the given type
    </summary>
    <typeparam name="T">the type of the item to retrieve</typeparam>
    ...

The cref tag expects them in one of the following formats:

cref标签期望它们采用以下格式之一:

/// <seealso cref="M:My.Namespace.Class1.Get{T}(System.String)"/>   

/// <seealso cref="M:My.Namespace.Class1.Get&lt;T>(System.String)"/>   

#4


1  

I've had the same question, but with a generic Dictionary.Item(TKey) property. The answer by leppie

我有同样的问题,但有一个通用的Dictionary.Item(TKey)属性。莱比的答案

<see cref="P:System.Collections.ArrayList.Item(System.Int32)" />

and the additional link by ICR (unfortunately I cannot find the "mscorlib.xml")

和ICR的附加链接(遗憾的是我找不到“mscorlib.xml”)

MSDN: Processing the XML File (C# Programming Guide)

MSDN:处理XML文件(C#编程指南)

helped me out.

帮帮我了

But the answer by user492238
(I know, I should directly comment his answer. But since I am new and this is my first post, please go easy on me, because I am not allowed to comment due to my low reputation.)

但是用户的回答492238(我知道,我应该直接评论他的答案。但是因为我是新人,这是我的第一篇文章,请放轻松我,因为我的声誉很低,所以不允许发表评论。)

<seealso cref="M:My.Namespace.Class1.Get{T}(System.String)"/>
<seealso cref="M:My.Namespace.Class1.Get&lt;T>(System.String)"/>

(System.String)”/>

resulted only in plain, black text, whereby only the seconds shows tag signs <> as given "hard-coded".

仅产生纯黑色文本,其中只有秒显示标记符号<>给出“硬编码”。

I found the solution on the MSDN page to use backticks (`) for generics and got a full ("colory") references to the class and property within my XMLDoc:

我在MSDN页面上找到了解决方案,使用反引号(`)表示泛型,并获得了对XMLDoc中类和属性的完整(“colory”)引用:

    <see cref="P:System.Collections.Generic.Dictionary`2.Item(`0)" />
Dictionary<TKey, TValue>.this[TKey]

#5


1  

<see cref="ReadOnlyCollection{T}.this[int]" />

as proposed here.

这里提出的。

#1


11  

<see cref="P:System.Collections.ArrayList.Item(System.Int32)" />

#2


5  

<see cref="this[int]" />

#3


1  

In general, in order to find out, how to reference any member in your comments, find the member in your XML documentation file for the assembly. It is created on each build. With the only exception of generics the member reference can be taken from here:

通常,为了找出如何引用注释中的任何成员,请在XML文档文件中找到该程序集的成员。它是在每个构建上创建的。除了泛型之外,成员参考可以从这里获取:

</member>
<member name="P:My.Namespace.Class1.Item(System.String)">
    <summary>
       retrieve a single item of the given name from this instance
    </summary>
    <param name="name">name of the item</param>
    <returns>the item</returns>
</member>
<member name="M:My.Namespace.Class1.Function1(System.Int32[])">
    <summary> 
    ... 

Unfortunately, generic definition formats seem not to be compatible between the documentation file and the cref tags. While in the XML file, generics look like that:

不幸的是,通用定义格式似乎在文档文件和cref标签之间不兼容。在XML文件中,泛型看起来像这样:

<member name="M:My.Namespace.Class1.Get``1(System.String)">
    <summary>
    retrieve an named item of the given type
    </summary>
    <typeparam name="T">the type of the item to retrieve</typeparam>
    ...

The cref tag expects them in one of the following formats:

cref标签期望它们采用以下格式之一:

/// <seealso cref="M:My.Namespace.Class1.Get{T}(System.String)"/>   

/// <seealso cref="M:My.Namespace.Class1.Get&lt;T>(System.String)"/>   

#4


1  

I've had the same question, but with a generic Dictionary.Item(TKey) property. The answer by leppie

我有同样的问题,但有一个通用的Dictionary.Item(TKey)属性。莱比的答案

<see cref="P:System.Collections.ArrayList.Item(System.Int32)" />

and the additional link by ICR (unfortunately I cannot find the "mscorlib.xml")

和ICR的附加链接(遗憾的是我找不到“mscorlib.xml”)

MSDN: Processing the XML File (C# Programming Guide)

MSDN:处理XML文件(C#编程指南)

helped me out.

帮帮我了

But the answer by user492238
(I know, I should directly comment his answer. But since I am new and this is my first post, please go easy on me, because I am not allowed to comment due to my low reputation.)

但是用户的回答492238(我知道,我应该直接评论他的答案。但是因为我是新人,这是我的第一篇文章,请放轻松我,因为我的声誉很低,所以不允许发表评论。)

<seealso cref="M:My.Namespace.Class1.Get{T}(System.String)"/>
<seealso cref="M:My.Namespace.Class1.Get&lt;T>(System.String)"/>

(System.String)”/>

resulted only in plain, black text, whereby only the seconds shows tag signs <> as given "hard-coded".

仅产生纯黑色文本,其中只有秒显示标记符号<>给出“硬编码”。

I found the solution on the MSDN page to use backticks (`) for generics and got a full ("colory") references to the class and property within my XMLDoc:

我在MSDN页面上找到了解决方案,使用反引号(`)表示泛型,并获得了对XMLDoc中类和属性的完整(“colory”)引用:

    <see cref="P:System.Collections.Generic.Dictionary`2.Item(`0)" />
Dictionary<TKey, TValue>.this[TKey]

#5


1  

<see cref="ReadOnlyCollection{T}.this[int]" />

as proposed here.

这里提出的。