如何为我们的方法和属性设置简要说明. [英] How to set a brief for our Methods and Properties.

查看:73
本文介绍了如何为我们的方法和属性设置简要说明.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

专家们

我上课了

Hi experts

I made a class

public class Test
{
   public Name {get; set;}
   

   public void SetName()
   {
       // code
   }
}



例如,当您键入Conosole时,您看到了Visual Studio自动完成功能.写入后会显示一个工具提示并说:



You saw visual studio autocomplete for example when you type Conosole.Write then a tooltip is shown and says:

void Console.Write(string value) (+17 overload(s))
Write the specific string value to the standard output stream.

Exceptions:
   System.IO.IOException



我上课要这样的东西.我使用了Description属性,但没有用.



I want something like this for my class. I used Description attribute but it did not work.

public class Test
{
  [Description("Something1"]
   public Name {get; set;}
   
  [Description("Something2"] 
  public void SetName()
  {
       // code
  }
}



问题是:如何为我的方法和属性设置一些描述,使其在其他程序员使用该类时可以显示出来.就像一些内置类.

感谢



The question is: How can set some description for my mehtods and properties that it can be shown when the other programmers are using the class. like some built in classes.

thanks

推荐答案

/// <summary>
/// Sets the name of the widget.
/// </summary>
public void SetName()
{
    // ...
}


这个问题的表述方式不是很清楚,但是我想您需要代码的文档才能出现在Visual Studio Intellisense中(它并不是自动完成的,但是有些更高级的功能).

您的方向错误:属性是为不同目的设计的.这些属性可以通过反射来影响运行时行为,但是您不希望使用仅在开发期间需要通过Visual Studio使用或不需要的东西来污染您的代码.因此,Visual Studio支持完全不同的机制,称为XML文档注释.

想法是这样的:您用特殊注释注释某些类型和成员,从C#的角度来看,它们像常规注释一样工作,但由Visual Studio以特殊方式处理.特殊注释定界符可识别此类注释:
The question is not very clearly formulated, but I guess you need the documentation of your code to appear in Visual Studio Intellisense (which is not really auto-complete but some more advanced functionality).

You are looking in wrong direction: attributes are designed for very different purposes. The attributes can affect run-time behavior through Reflection, but you don''t want to contaminate your code with something which is only needed during development, through Visual Studio or not. Therefore, Visual Studio supports completely different mechanism called XML Documentation Comments.

The idea is this: you comment some of your types and members with special comments which works like regular comments from the standpoint of C# but are processed in a special way by Visual Studio. Such comments are recognized by special comment delimiters:
///


/** 
...
*/



如您所见,C#通过这种方式将标记视为注释.在要记录的类型或成员之前的一行开始输入"///",Visual Studio将为您创建一个简约的注释模板.

在此类注释中,您可以编写特殊格式的XML文档来表示方法,参数,交叉引用等.

请参阅:
http://msdn.microsoft.com/en-us/library/b2s063f7.aspx [ ^ ].

它会在一个特殊文件中创建文档,默认情况下会创建该文件并将其仅用于Debug配置,但是您可以在项目属性中对其进行更改-请参见构建"选项卡"XML文档文件".

享受,

—SA



As you can see, in this way C# recognized such markup as comments. Start typing "///" one the line before a type or a member to be documented, and Visual Studio will create a minimalistic comment template for you.

Inside such comments, you can write specially formatted XML documentation to denote methods, parameters, cross-references, etc.

Please see:
http://msdn.microsoft.com/en-us/library/b2s063f7.aspx[^].

It creates the documentation in a special file which is, by default, is created and used only for Debug configuration, but you can change it in the project properties — please see the tab "Build", "XML Documentation file".

Enjoy,

—SA


这篇关于如何为我们的方法和属性设置简要说明.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆