O'Reilly logo

Applied Microsoft® .NET Framework Programming by Jeffrey Richter

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detecting the Use of a Custom Attribute

Defining an attribute type is useless by itself. Sure, you could define attribute types all you want and apply them all you want; but this would just cause additional metadata to be written out to the managed module—the behavior of your application code wouldn’t change.

In Chapter 13, you saw that applying the Flags attribute to an enumerated type altered the behavior of System.Enum’s ToString, Format, and Parse methods. The reason these methods behave differently is that they check at run time whether the enumerated type they’re operating on has the Flags attribute metadata associated with it. Code can look for the presence of attributes using a technology called reflection. I’ll give some brief demonstrations ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required