May 2010
Intermediate to advanced
1752 pages
41h 17m
English
The first step in building a custom attribute is to create a new class deriving from System.Attribute. Keeping in step with the automobile theme used throughout this book, assume you have created a brand new C# Class Library project named AttributedCarLibrary. This assembly will define a handful of vehicles, each of which is described using a custom attribute named VehicleDescriptionAttribute:
// A custom attribute.
public sealed class VehicleDescriptionAttribute : System.Attribute
{
public string Description { get; set; }
public VehicleDescriptionAttribute(string vehicalDescription)
{
Description = vehicalDescription;
}
public VehicleDescriptionAttribute(){ }
}
As you can see, VehicleDescriptionAttribute maintains ...