C#.NET - Trying to understand square bracket syntax in DataSource definition

jdana
jdana used Ask the Experts™
on
I’m still in the process of getting up to speed with C#.  I found this definition of the DataSource property in System.Windows.Forms.dll.  Can someone tell me what’s up with the square bracket notation above public object DataSource { get; set; }?  I recognize there’s a lot of code there.  I’m simply trying to get a handle on the square brackets.
//
// Summary:
//     Gets or sets the data source that the connector binds to.
//
// Returns:
//     An System.Object that acts as a data source. The default is null.
[SRCategory("CatData")]
[SRDescription("BindingSourceDataSourceDescr")]
[DefaultValue("")]
[RefreshProperties(RefreshProperties.Repaint)]
[AttributeProvider(typeof(IListSource))]
public object DataSource { get; set; }

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Those are attributes, and they affect the way the compiler and/or runtime deals with the code. Attributes can be used in many different ways, so it's difficult to give you an all-encompassing definition. For example, when performing XML serialization, you can instruct the runtime to not include an arbitrary property by tagging it with the XmlIgnore attribute:

public class SomeClass
{
    [System.Xml.Serialization.XmlIgnore()]
    public string SomeProperty { get; set; }
}

Open in new window


Another example is that of using Windows API calls. To import a library, you can use the DllImport attribute:

[DllImport("user32.dll")]
static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);

Open in new window


So it depends on the attribute as to what the attribute affects.

Author

Commented:
kaufmed,

Thanks for the superlative description.  I appreciate it.

J

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial