我想知道是否可以在注释中引用动态通用类名并在 IDE 中有条件地解析它?
简单的基类示例:
// <summary>
// Retrieves all <T> members from the database.
// </summary>
public void GetAll<T>()
{
//magic
}
如果我现在继承自此类并且恰好是 User 类,那么我希望 IntelliSense 将我的评论显示为“从数据库中检索所有用户成员”。
这可能吗?
最佳答案
无法让 Intellisense 自动写入用于特定调用的通用类型的名称。你能做的最好的就是使用 typeparamref
标记,它向 Visual Studio(更重要的是任何文档生成器)指示您指的是泛型类型参数(在本例中为 T
)。
// <summary>
// Retrieves all <typeparamref name="T"/> members from the database.
// </summary>
public void GetAll<T>()
{
//magic
}
关于c# - 引用通用评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/930819/