属性的DescriptionAttribute与<summary>标记

Joh*_*6NY 5 .net c# visual-studio-2005 xml-documentation visual-studio

我在VS 2005下用C#编写了一个类库(我知道,现代化,但我们这里的预算很紧张).

在我看来,如果我在XML文档中使用"summary"标记,我的用户可以通过Intellisense和工具提示等查看该信息,但不能在Studio的"属性"窗口中看到.

要在该窗口中获取某些内容,我似乎需要使用[Description("This is it")]属性.

我对此是否正确?如果是这样,那么我似乎需要复制描述信息:-(

或者,还有更好的方法?谢谢!

Cod*_*ray 7

对,那是正确的.这两种方法的目的截然不同.

  • 这些/// <summary></summary>注释用于在编译时为您的项目生成XML文档,Visual Studio也会针对其IntelliSense数据库对其进行解析.

  • [DescriptionAttribute]规定是在设计中,最值得注意的是,在属性窗口的底部说明文字.

微软自己的Windows窗体库充斥着这两者.

我不知道有什么方法可以将两者合并,但考虑一下你是否真的希望它们完全相同.在我自己的类库中,我经常希望在设计器中显示的信息与我想要包含在技术文档中的信息略有不同.

举一个简单的例子,我可能想在设计器中明确说明某些版本的Windows不支持此属性,但将此信息转发到<remarks>我的技术文档中的部分:

/// <summary>
/// Gets or sets a value indicating whether a shield should be displayed
/// on this control to indicate that process elevation is required.
/// </summary>
/// <remarks>
/// The elevation-required shield is only supported under Windows Vista
/// and later. The value of this property will be ignored under earlier
/// operating systems.
/// </remarks>
[Category("Appearance")]
[Description("Displays a shield to indicate that elevation is required. " +
             "(Only applies under Windows Vista and later.)")]
public bool ShowShield { get; set; }
Run Code Online (Sandbox Code Playgroud)