添加属性的描述

时间:2010-09-30 16:28:43

标签: c#

如何为我的媒体添加文字说明?

alt text

我的代码:

private bool _SpaceKey;

public bool SpaceKey
{
    get
    {
        return _SpaceKey;
    }
    set
    {
        _SpaceKey = value;
    }
}

4 个答案:

答案 0 :(得分:25)

查看Description Attribute

[Description("This is the description for SpaceKey")]
public bool SpaceKey { get; set; }

您还可以使用Category Attribute指定属性的类别:

[Category("Misc")]
[Description("This is the description for SpaceKey")]
public bool SpaceKey { get; set; }

答案 1 :(得分:10)

如果您想在Visual Studio设计器(或任何其他兼容的IDE)中看到描述,则需要使用design-time attributes for components中定义的System.ComponentModel命名空间。

[Description("This is the description of Space Key.")]
public bool SpaceKey { get; set; }

在此之前,请考虑学习如何从类库中的描述中编写好的描述(尽管它们并不总是有用)。遵循现有的风格是很好的。

如果您想在代码中看到提示,例如选择使用IntelliSense的成员时的工具提示,您还需要使用XML comments作为文档:

/// <summary>
/// Gets or sets space key (that would probably make a bad summary).
/// </summary>
public bool SpaceKey { get; set; }

就是这样。

答案 2 :(得分:1)

(有点晚但可能对某人有帮助)

您可以使用的另一个选项是:

[Browsable(true)]

如果Browsabletrue,您可以在属性窗口中看到属性,当它的false时,没有人无法通过设计器中的属性窗口更改它。 请参阅more information

答案 3 :(得分:1)

Asp.net Core c#编码中,它是不同的。其所有asp.net核心版本的工作。

 [Display(Name = "Employee Name")]  
 public string EmployeeName { get; set; }