参考通用评论

Ale*_*lex 7 c# intellisense xml-documentation xml-comments visual-studio

我想知道是否可以在注释中引用动态泛型类名称并在IDE中有条件地解决它?

简单的基类示例:

// <summary>
// Retrieves all <T> members from the database.
// </summary>
public void GetAll<T>()
{
 //magic
}
Run Code Online (Sandbox Code Playgroud)

如果我现在从这个类继承而恰好是类User,那么我想让IntelliSense将我的评论显示为"从数据库中检索所有用户成员".

这可能吗?

Nol*_*rin 4

无法让 Intellisense 自动写入用于特定调用的泛型类型的名称。您能做的最好的事情就是使用typeparamref标记,它向 Visual Studio(更重要的是任何文档生成器)表明您正在引用泛型类型参数(T在本例中)。

// <summary>
// Retrieves all <typeparamref name="T"/> members from the database.
// </summary>
public void GetAll<T>()
{
    //magic
}
Run Code Online (Sandbox Code Playgroud)