为谓词帮助器类编写一些 XML 文档。 但我不知道我可以引用 Expression>
而不会出现语法错误。 有可能吗? 我已经尝试过:
<see cref="Expression{Func{T, bool}}"/>
但是我在 {T, bool}}
下看到一条红色的波浪线。 但这是有效的:
<see cref="Expression{TDelegate}"/>
有人有线索吗?
更新:
给出的答案(我接受了)似乎确实有效。 但现在我开始收到很多关于无法解决问题的警告。 我有一个名为 ExpressionBuilder
的类,它经常与 Expression>
配合使用。 所以我当然想在我的 XML 注释中引用这一点。
我已经尝试过我所知道的两个版本:
<see cref="Expression<Func<T, Boolean>>"/>
<see cref="Expression{Func{T, Boolean}}"/>
但都不起作用。 (在最后一个,ReSharper 在 {T,Boolean}}
下放置了一个蓝色的波浪线,我在使用它的所有地方的编译下都会收到两个警告,其中表示:
- “blah blah”的 XML 注释具有 cref 属性“Expression>” 无法解决
- 类型参数声明必须是标识符而不是类型。 另请参阅错误 CS0081。
在我尝试引用 Range>
的地方遇到了同样的问题(Range
也不起作用。无论是 { } 还是 < code><>)
我不应该引用这些类型的泛型吗?
Writing some XML documentation for a predicate helper class. But I can't figure out I can refer to an Expression<Func<T, bool>>
without getting a syntax error. Is it even possible? I have tried this:
<see cref="Expression{Func{T, bool}}"/>
But I get a red squiggly line under {T, bool}}
. This works though:
<see cref="Expression{TDelegate}"/>
Anyone have a clue?
Update:
The answer that was given (and I accepted) seemingly did work. But now I have started to get a lot of warnings about stuff not being able to resolve. I have a class called ExpressionBuilder<T>
which works with Expression<Func<T, bool>>
a lot. So I of course want to refer to that in my XML comments.
I have tried both versions that I know about:
<see cref="Expression<Func<T, Boolean>>"/>
<see cref="Expression{Func{T, Boolean}}"/>
But neither work. (And on the last one, ReSharper puts a blue squiggly under {T,Boolean}}
I get two warnings under compilation everywhere I have used it which says that:
- XML comment on 'blah blah' has cref attribute 'Expression>' that could not be resolved
- Type parameter declaration must be an identifier not a type. See also error CS0081.
Have the same issue somewhere I tried to refer to Range<Nullable<DateTime>>
(Range<DateTime?>
didnt work either. Both with { } and with < >
)
Am I not supposed to refer to these kinds of generics?
发布评论
评论(7)
似乎没有办法在 XML 文档中引用泛型的泛型,因为实际上,没有办法引用任何特定类型的泛型。
Lasse V Karlsen 的答案让我觉得很有趣:
如果您编写
,编译器仅使用“Int32”作为类型参数名称,而不是类型参数。 编写
也同样有效。 这是有道理的,因为 MSDN 中没有您的文档可以链接到的“IEnumerable of int”的特定页面。为了正确记录你的课程,我认为你必须写一些类似的内容:
我希望你喜欢文字。
There seems to be no way to refer to a generic of a generic in XML documentation, because actually, there's no way to refer to a generic of any specific type.
Lasse V Karlsen's answer made it click for me:
If you write
<see cref="IEnumerable{Int32}" />
, the compiler just uses "Int32" as the type parameter name, not the type argument. Writing<see cref="IEnumerable{HelloWorld}" />
would work just as well. This makes sense because there is no specific page in MSDN for "IEnumerable of int" that your documentation could link to.To document your class properly, I think you'd have to write something like:
I hope you like text.
您到底希望它链接到什么?
文档中没有
Expression>
这样的东西,所以显然指向它的链接是行不通的。您可以链接到
Expression
因为它存在。至于什么有效或无效,以下两种方法在 Visual Studio 2008 / .NET 3.5 中对我来说都不起作用:
但这有效:
所以显然泛型类型参数不必与声明中的参数相同。
What exactly would you like it to link to?
There's no such thing in the documentation as a
Expression<Func<T>>
, so obviously a link to that would not work.You can link to
Expression<TDelegate>
because that exists.As for what works or not, neither of the following works in Visual Studio 2008 / .NET 3.5 for me:
But this works:
so apparently the generic type parameter doesn't have to the same as the one in the declaration.
不要使用空的 see 元素 (
)。 相反,将文本放入 see 元素内Don't use an empty see element (
<see cref="..." />
). Instead, put text inside the see element我现在遇到了这个问题,因为我有一个返回
List
的函数。 是的,很丑,但不是我写的。 标准免责声明,我知道。>
不管怎样,在 VS 2017 和 R# Ultimate 2017.1 中,这个文档注释...
...给了我一个语法错误。 然而,这个...
...没有。 Eeeenteresting。
还是丑? 是的。
丑陋? 我认为这比我自己使用
<
和>
没那么可怕......I'm running into this now, as I have a function that returns a
List<List<byte>>
. Yeah, it's ugly, but I didn't write it. Standard disclaimer, I know.Anyway, in VS 2017 with R# Ultimate 2017.1, this doc comment...
...gives me a syntax error. However, this...
<returns><see><cref>List{List{byte}}</cref></see> of split frames</returns>
...does not. Eeeenteresting.
Still ugly? Yes.
As ugly? I think it's less horrible than using
<
and>
myself....我尝试了有关堆栈溢出的所有方法,以获得在多种情况下工作的结果。 这是一个适合我的解决方案。 (这对其他人来说是主观的。)
示例#1
示例#2(使用“T”)
I tried everything on stack overflow to a get results that work under several scenarios. Here's a solution that works for me. (That's subjective concerning anyone else.)
Example #1
Example # 2 (using "T")
我来使用这个:
应用到你的OP这里结果:
这里是IntelliSense弹出窗口的图像:
I came to use this:
Applied to your OP here the result:
Here the image of the IntelliSense pop-up: