Lecture overview -- Keyboard shortcut: 'u'  Previous page: Serialization and Alternatives -- Keyboard shortcut: 'p'  Next page: Patterns and Techniques [Section] -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 36 : 40
Object-oriented Programming in C#
Input and Output Classes
Attributes

Attributes offer a mechanism that allows the programmer to extend the programming language in simple ways.

Attributes can be accessed by the compiler and - at run-time - by the interpreter

/user/normark/oop-csharp-1/sources/c-sharp/io/attributes/1/prog.csAn obsolete class C, and a class D with an obsolete method M.


/user/normark/oop-csharp-1/sources/c-sharp/io/attributes/1/compilingCompiling class C, D, and E.


  • The attribute Obsolete is defined by a predefined class ObsoleteAttribute

    • A subclass of System.Attribute

    • Positional attribute parameters correspond to constructor parameters

    • Named attribute parameters specify assignment to properties

/user/normark/oop-csharp-1/sources/c-sharp/io/attributes/1/obsolete.csA reproduction of class ObsoleteAttribute.


/user/normark/oop-csharp-1/sources/c-sharp/io/attributes/1/usage-obsolete.csSample usage of the reproduced class - causes a compilation error.