Programming with Attributes

.NET makes practical use of an attributed programming system that allows objects or methods to be extended in a particular way. C# has no provision for templates or macros. These are well known to C++ programmers as a way to aggregate functionality or provide cookie cutter behaviors. Attributes, like macros or templates, insert code into your software that applies certain rules to replaceable elements. For example, it is possible to turn a seemingly mundane C# class with three or four lines of code into a full-blown Internet Web service by using the attribute [WebMethod] in the source code. Using this technique, it is possible to create something akin to a full IIS server extension DLL in just a few moments, and have ...

Get C# and the .NET Framework: The C++ Perspective now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.