如何为自定义创建的类获取intellisense?

当您输入“this”时。 ,你通常会得到你所在的当前课程的所有例程,事件等等。当你只是站在长列表中的一个例程而不选择一个例程时,你通常会在它旁边得到一个描述。

我怎样才能做到这一点 ? 假设我有一个名为CAR的类,它有两个例程:speed_up()和brake()。 当他输入时,如何让使用我的class级的人看到这两个函数的描述:

CAR mycar = new CAR(); mycar. 

在类或方法之上,而不是“//”注释。 如果你执行“///”三次斜杠(也称为XML注释),它会执行一个快捷方式,以便您填写有关您正在评论的类或方法的信息。

然后,这会出现在您的代码中

  ///  /// ///  ///  ///  void Method(object sender, EventArgs e) 

然后,当您通过intellisense访问类或方法时,将出现描述。

为您的课程及其成员提供XML注释 ,这些注释将出现在intellisense中 。 在visual studio中执行此操作的最简单方法是在///上方输入要添加注释的内容。

例如:

 ///  /// Class level summary documentation goes here. ///  /// Longer comments can be associated with a type or member through /// the remarks tag. public class TestClass : TestInterface { ///  /// Store for the name property. private string _name = null; ///  /// The class constructor.  public TestClass() { } ///  /// Description for SomeMethod. ///  Parameter description for s goes here. ///  /// You can use the cref attribute on any tag to reference a type or member /// and the compiler will check that the reference exists.  public void SomeMethod(string s) { } } 

以上是在这里找到的。


另请参阅: 如何使XML注释出现在其他项目(dll)中?

您应该使用Visual Studio中可用的XML文档格式来处理每种类型的构造(即类,方法,属性……)

要访问它,请在声明之前在行上键入///。

例如:

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

你会得到类似的东西:

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

如果你键入/// <你甚至会得到可用的XML元素列表,比如备注或例子有关更多信息,请参阅http://msdn.microsoft.com/en-us/magazine/cc302121.aspx

你可以这样写评论:

 ///  /// This sppeds up the car ///  public void speed_up() { } 

你必须像这样评论它:

 ///  /// This is my function. ///  /// This parameter is very important. /// It returns always 42. public int MyFunction(string myParameter) { return 42; } 

您可以描述函数

的用法以及参数的含义。 如果函数具有返回值,则可以使用标记来描述它。 有一些mor标签支持,当你在三个\之后写评论时,它将由visual studio列出。

尝试通过键入///添加摘要到您的方法,并填写如下

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

您可以为每个方法和属性执行此操作,以便在Intellisense中有意义地显示intent。

您需要为方法添加文档注释。 您可以通过键入“///”或使用visual studio addin手动完成此操作。 如果您遵循良好的命名约定, GhostDoc添加将帮助您解决这个问题。