Cha*_*lts 6 c# generics comments visual-studio
给出这样的方法:
/// <summary>
/// Given a <see cref="T1"/>, return a <see cref="T2"/>.
/// </summary>
public T2 ExampleMethod(T1 t1)
{
// omitted
}
Run Code Online (Sandbox Code Playgroud)
我可以编写一个注释,以便Visual Studio能正确显示它,例如,如果T1是一个int而T2是一个string吗?或者,我是否坚持T1和T2出现在评论中?
换句话说:有什么我可以这样做的,在Visual Studio中,此方法的工具提示显示实际的类型名称?
编辑:我似乎没有解释我真正感兴趣的是什么.
假设我有一个叫做的课程Widget<T1,T2>.假设我有一个类似上面的方法.
然后,当我这样做
Widget<int,string> myExample = new Widget<int,string>();
myExample.ExampleMethod(... ); // HERE - if I mouse over the method
// I get a tooltip. Is there something I can do to the comment in my
// example method above that will allow me to say
// "Given a System.Int32, return a System.String"?
Run Code Online (Sandbox Code Playgroud)
编辑2:刚才有人在这里发表评论,但他们的评论被删除了.他们建议我用
///Given a <see cref="T1"/>, return a <see cref="T2"/>.
Run Code Online (Sandbox Code Playgroud)
这就是我现在正在使用的.这可以.我的问题,现在第三次用不同的方式,Visual Studio足够聪明,可以推断T1和T2来自构造函数?我可以从方法签名中找出T1和T2是什么,我想也许Visual Studio可以做同样的事情并在评论中支持这一点.
我的直觉不是,但因此问题.
不,Visual Studio 不支持这一点。您应该问自己为什么要在评论中使用特定类型。
好的方法文档是通过用非技术术语描述其功能来完成的。并通过使用清晰的名称和良好的描述来描述其参数,该参数的期望是什么。这种类型几乎不需要。如果您确实需要它,您可能正在尝试以技术方式记录您的方法,这几乎不是一个好主意。