28.1. An attribute class
Using a custom attribute involves writing an attribute class first. Let's examine an example of a custom attribute class called AuthorAttribute: [1]
[1] You will have noticed that I have deliberately made my class fields public. This is, of course, lousy programming practice. The reason is that my reflection codes need to access these fields in a later example. What I should have done, in accordance with good programming practice, is to make these fields private and 'expose' them using public properties. But, for now, I do not wish to complicate issues, especially for those who have not yet read Chapter 20. I will have to bring in properties eventually, in section 28.4.1, but for now, just bear with my public fields.
Get From Java to C#: A Developer's Guide 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.