简体   繁体   English

为什么我们在C#中为类属性使用description属性

[英]why we use description attribute for class property in c#

i saw in some code that use Description attribute for class property and i couldn't find reason of behavior in c# codding 我在一些使用Description属性作为类属性的代码中看到了,但是我找不到C#编码中的行为原因

 public class sample
    {
        [Description("description1")]
        public string PropertyOnne{ get; set; }

     }

for readability of code we can use xml summary for even property and i didn't understand what is difference between summary and Description attribute in class level. 为了提高代码的可读性,我们可以将xml摘要用于偶数属性,而我不理解在类级别的summary和Description属性之间有什么区别。

This is for visual designers, they can display the description when referencing them. 这是针对视觉设计师的,他们可以在引用它们时显示说明。

Remark from the docs: 从文档备注:

A visual designer can display the specified description when referencing the component member, such as in a Properties window. 当引用组件成员时,可视设计器可以显示指定的描述,例如在“属性”窗口中。 Call Description to access the value of this attribute. 调用说明以访问此属性的值。

Source: https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.descriptionattribute?view=netframework-4.7.2 来源: https : //docs.microsoft.com/zh-cn/dotnet/api/system.componentmodel.descriptionattribute?view=netframework-4.7.2

Simple words, you can consider below explanation 简单的话,你可以考虑下面的解释

  • The tag is used to generate documentation in XML for your Project at Compile time, this is also used by the visual studio for its intellisense database 该标记用于在编译时为您的项目生成XML文档,Visual Studio还将其用于其智能感知数据库

  • The Description attribute used by the designer in order to understand the text, mostly at the bottom of the property window(for reference). 设计人员用来理解文本的Description属性,通常位于属性窗口的底部(仅供参考)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM