如何为我的媒体添加文字说明?
我的代码:
private bool _SpaceKey;
public bool SpaceKey
{
get
{
return _SpaceKey;
}
set
{
_SpaceKey = value;
}
}
答案 0 :(得分:25)
[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)]
如果Browsable
是true
,您可以在属性窗口中看到属性,当它的false
时,没有人无法通过设计器中的属性窗口更改它。
请参阅more information。
答案 3 :(得分:1)
在Asp.net Core c#编码中,它是不同的。其所有asp.net核心版本的工作。
[Display(Name = "Employee Name")]
public string EmployeeName { get; set; }