参考一般性评论

7

我想知道是否可能在注释中引用一个动态的泛型类名,并且在IDE中有条件地解析它?

简单的基础类示例:

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

如果我现在从这个类继承并且恰好是类 User,那么我希望 IntelliSense 将我的注释显示为“从数据库检索所有用户成员”。

这可能吗?

1个回答

4

无法让Intellisense自动写入用于特定调用的泛型类型名称。最好的方法是使用typeparamref标签,这会告诉Visual Studio(更重要的是任何文档生成器),你正在引用泛型类型参数(在本例中为T)。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接