什么是括号[]在下面的code是什么意思? [英] What does square bracket [] mean in the below code?
问题描述
我有以下code从<一个href=\"http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx\">http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx在Web部件工具窗格中添加自定义属性。什么括号( []
),在下面的code是什么意思?
[类别(自定义属性)]
[WebPartStorage(Storage.Personal)
[FriendlyNameAttribute(自定义颜色)
[说明(选择从下拉列表中选择一种颜色。)
[可浏览(真)]
[XmlElement的(typeof运算(System.Drawing.KnownColor))]
公共System.Drawing.KnownColor MyColor
{
得到
{
返回_myColor;
}
组
{
_myColor =价值;
}
}
由于@Spencer Ruport说,他们的属性。他们.NET中用于声明式编程。
您可以找到这些属性在MSDN的信息。然而,你应该知道属性的名称可以缩短。在你的情况,例如,类别
是类名的缩写形式的CategoryAttribute
和的XmlElement
是类名的缩写形式 XmlElementAttribute
。当声明属性,类名的属性
部分可以省略。
的PropertyGrid
控制相结合(见<αhref=\"http://www.c-sharpcorner.com/UploadFile/mgold/PropertyGridInCSharp11302005004139AM/PropertyGridInCSharp.aspx\">here的例子),但在你的情况,它们用于在Web部件属性窗格。的目的仍然是相同的。这些属性用于控制要知道如何显示属性给用户。通过使用该控制理解的各种属性的组合,有可能的声明方式的口授此行为
我希望帮助一点点,但斯宾塞是正确的,你将了解通过谷歌的属性更大量的阅读,比我可以在这里解释一下。
I got below code from http://msdn.microsoft.com/en-us/library/dd584174(office.11).aspx for adding custom property in webpart tool pane. What does square bracket ([]
) mean in the below code?
[Category("Custom Properties")]
[WebPartStorage(Storage.Personal)]
[FriendlyNameAttribute("Custom Color")]
[Description("Select a color from the dropdown list.")]
[Browsable(true)]
[XmlElement(typeof(System.Drawing.KnownColor))]
public System.Drawing.KnownColor MyColor
{
get
{
return _myColor;
}
set
{
_myColor = value;
}
}
As @Spencer Ruport said, they're attributes. They're used within .NET for declarative programming.
You can find information on each of these attributes at MSDN. However, you should know that the name of the attribute can be shortened. In your case, for example, Category
is the short form of the class name CategoryAttribute
and XmlElement
is the short form of the class name XmlElementAttribute
. When declaring attributes, the Attribute
portion of the class name can be left out.
I've used most of these attributes in conjunction with the PropertyGrid
control (see here for an example), although in your case, they are used for a Web Part property pane. The purpose is still the same. The attributes are used by the control to know how to display the property to the user. By using a combination of the various attributes that the control understands, it is possible to declaratively dictate this behavior.
I hope that helps a little bit, but Spencer is correct, you'll learn a lot more reading about attributes via Google than I can explain here.
这篇关于什么是括号[]在下面的code是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!