O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

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

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.

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