2011-11-23 41 views
10

当你输入“this”。 ,你通常会获得当前所在班级的所有例程,活动等等。而当你仅仅站在长列表中的一个例程而没有选择一个例程时,通常会在它旁边获得一个说明。如何获得自定义创建的类的智能感知?

我该怎么做?假设我有一个名为CAR的类有两个例程:speed_up()和brake()。 我怎样才能让使用我班看到的这两个功能的描述,当他类型的人:

CAR mycar = new CAR(); 
mycar. 

回答

23

以上一类或方法,而不是一个 “//” 的评论。如果你做了一个“///”三重斜杠(或者称为XML注释),它会执行一个快捷方式,让你填写关于你正在评论的类或方法的信息。

这然后在代码中出现这样

/// <summary> 
    /// 
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    void Method(object sender, EventArgs e) 

当你再通过智能感知,多数民众赞成访问类或方法时,描述将出现。

+0

它很简单。 :D谢谢。 – Fares

+0

我发现了与名称空间相结合的Intellisense问题:[link] http://stackoverflow.com/questions/23562307/intellisense-not-shown-on-public-classes-but-on-private-ones [link] can you确认? –

8

给你的类及其成员,XML comments,将出现在intellisense。在Visual Studio中最简单的方法是在你想添加注释的地方输入///

例如:

/// <summary> 
/// Class level summary documentation goes here.</summary> 
/// <remarks> 
/// Longer comments can be associated with a type or member through 
/// the remarks tag.</remarks> 
public class TestClass : TestInterface 
{ 
    /// <summary> 
    /// Store for the name property.</summary> 
    private string _name = null; 

    /// <summary> 
    /// The class constructor. </summary> 
    public TestClass() { } 

    /// <summary> 
    /// Description for SomeMethod.</summary> 
    /// <param name="s"> Parameter description for s goes here.</param> 
    /// <seealso cref="System.String"> 
    /// You can use the cref attribute on any tag to reference a type or member 
    /// and the compiler will check that the reference exists. </seealso> 
    public void SomeMethod(string s) 
    { 
    } 
} 

上述发现here


参见:How do you get XML comments to appear in a different project (dll)?

+1

我觉得斜杠是另一种方式像'///' – V4Vendetta

+0

哎呀,刚才注意到了,谢谢。 –

2

试图通过///键控和填补像下面

/// <summary> 
/// This is my speed up method 
/// </summary> 
public void speed_up(){ ...} 

你能做到这一点每一个的方法和属性,使得它有意义显示在智能感知意图添加总结你的方法。

3

你应该使用在Visual Studio中提供的XML文档格式的每一种类型的结构(即类,方法,属性...)

要访问它,在你的声明之前线型///。

例如:

/// 
    public void Method(string p){... 

你会得到这样的:

/// <summary> 
    /// 
    /// </summary> 
    /// <param name="p"></param> 
    public void Method(string p){... 

如果键入/// <,你甚至会得到可用的XML元素的列表,如言论或为例 欲了解更多信息,请参阅http://msdn.microsoft.com/en-us/magazine/cc302121.aspx

2

您可以将此意见放入:

/// <summary> 
/// This sppeds up the car 
/// </summary> 
public void speed_up() 
{ } 
2

你必须把一个评论对这样的:

/// <summary> 
/// This is my function. 
/// </summary> 
/// <param name="myParameter">This parameter is very important.</param> 
/// <returns>It returns always 42.</returns> 
public int MyFunction(string myParameter) 
{ 
    return 42; 
} 

你可以描述的功能<summary>的使用和PARAMATERS <param name="">的意义。如果函数具有返回值,则可以使用标记<returns>来描述它。当你在三个\之后写下你的评论时,有一些支持的mor标签将被视觉工作室列出。

1

您需要为方法添加文档注释。你可以通过输入'///'或使用visual studio插件手动完成。如果你遵循良好的命名约定GhostDoc添加将帮助你很多。

+0

我确实得到了intellisensefor自定义类的所有内容,但不包括解决方案中引用的任何自定义dll中的任何内容,尽管///在类和成员内工作... – gg89

相关问题