描述属性与<摘要>属性标签

发布于 2024-10-30 05:45:47 字数 286 浏览 2 评论 0原文

我正在 VS 2005 下用 C# 编写一个类库(我知道,与现代接轨,但我们这里的预算很紧张)。

在我看来,如果我在 XML 文档中使用“摘要”标签,我的用户可以通过 Intellisense 和工具提示等看到该信息,但不能在 Studio 的“属性”窗口中看到该信息。

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

我的说法正确吗?如果是这样,那么我似乎需要复制描述信息:-(

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

I'm writing a Class Library in C# under VS 2005 (I know, get with modern times, but we're on a tight budget here).

It appears to me that if I use a "summary" tag in the XML documentation, my users can see that info via Intellisense and tooltips, etc., but not in the Properties window in Studio.

To get something in that window, I seem to need to use a [Description("This is it")] attribute.

Am I correct on this? If so, then it would seem that I need to duplicate the description info :-(

Or, is there a better way? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

碍人泪离人颜 2024-11-06 05:45:47

是的,这是正确的。这两种方法有非常不同的目的。

  • ///

    注释用于在编译时为项目生成 XML 文档,Visual Studio 也会对其 IntelliSense 数据库进行解析。

  • [DescriptionAttribute] 提供设计器中使用的描述文本,尤其是在属性窗口的底部。

Microsoft 自己的 Windows 窗体库中充斥着这两种内容。

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

作为一个简单的示例,我可能想在设计器中明确指出,某些版本的 Windows 不支持此属性,但将此信息归入我的技术文档中的 部分:

/// <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; }

Yes, that's correct. The two methods have very different purposes.

  • The /// <summary></summary> comments are used to generate XML documentation for your project at compile-time, which is also parsed by Visual Studio for its IntelliSense database.

  • The [DescriptionAttribute] provides description text that is used in the designer, most notably at the bottom of the Properties Window.

Microsoft's own Windows Forms library is littered with both these.

I don't know of any way to merge the two, but consider whether you really want them to be exactly the same. In my own class libraries, I often want to display slightly different information in the designer than I want to include in my technical documentation.

As a simple example, I might want to make clear in the designer that this property is not supported under certain versions of Windows, but relegate this information to the <remarks> section in my tech docs:

/// <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; }
半衾梦 2024-11-06 05:45:47

摘要 XML 文档标签和描述属性是两个完全不同的东西

摘要标签用于组件的文档

DescriptionAttribute 是控件组件模型的一部分,并且在运行时应用程序中可用。这意味着信息被编译到您的二进制程序集文件中。应用程序的最终用户可以看到描述属性的内容(例如,当使用 PropertyGrid 控件时)。

如果您正在寻找文档,请仅使用 XML 文档。如果您希望创建可重用的组件,也可以使用“描述”属性。

A summary XML doc tag and a Description Attribute are two completely different things.

The summary tag is for use in the DOCUMENTATION for a component.

The DescriptionAttribute is part of the controls component model and is available within the application at run-time. That means that info gets compiled into your binary assembly file. The content of the Description Attribute can be visible to end users of your application (e.g. when using the PropertyGrid control).

If you are looking for documentation only use the XML doc. If you are looking to create a reusable component you may use the Description attribute, too.

失去的东西太少 2024-11-06 05:45:47

我的理解是你是对的。不过,您可以使用 GhostDoc 自动化大部分工作,它有一个免费版本,您可以自定义添加到您的描述属性中。

My understanding is that you are correct. However, you can automate most of this work by using GhostDoc, which has a free version that you can customize to add in your Description attribute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文