Im my opinion, a good example of the uses of attributes is when it comes to describing properties for the property explorer in Visual Studio.net.
using System;
using System.ComponentModel;
namespace Examples
{
public class ExampleControl : UserControl
{
private IndentStyle m_eExampleProperty = IndentStyle.Smart;
[
Category("Design"),
Description("Gets/sets an example value."),
DefaultValue(IndentStyle.Smart),
Browsable(true)
]
public IndentStyle ExampleProperty
{
get
{
return m_eExampleProperty;
}
set
{
m_eExampleProperty = value;
}
}
}
}
This would produce this kind of output:
If you want to try this out, just cut-and-paste the code into a source file, and create an instance of the control on the designer form. - Daniël Pelsmaeker
Microsoft is to quality software what McDonalds is to gourmet cooking