Attributes and Reflection

By: Jesse Miller

Attributes are a simple technique for adding metadata information and behavior to code within applications. Reflection technique can be used to pick up the attribute related information at runtime. An object is described by the values of its attributes. A car can be described by its make, model, and color. Similarly c sharp has certain attributes which depict and influence its behavior. Compiler instructions can be a perfect example.

An attribute is a declarative tag that is used to convey information at runtime about the behavior of programmatic elements such as classes, enumerators, and assemblies. A declarative tag is depicted by square ([ ]) brackets placed above the definition of an element such as a class or a method. Attributes are used for adding metadata, such as compiler instructions and other information such as comments, description, methods, and classes to a program.

The .NET Framework is equipped with a number of predefined attributes. The code to examine the predefined attributes and act upon the values they contain is also incorporated as a part of the runtime and .NET Framework Software Development Kit (SDK).

Attributes are applied to different elements of the code. These elements include assemblies, modules, classes, structs, enums, constructors, methods, properties, fields, events, interfaces, parameters, return values, and delegates. Information about attributes is stored with the metadata of the elements they are associated with.
An attribute name and its values are specified within square brackets ([ ]) before the element to which the attribute is applied. Attributes might require one or more parameters, positional or named.

Positional parameters are used to specify essential information of an attribute. The .NET Framework supports two categories of attributes to be used in C# programs. They are predefined and custom. Predefined attributes are supplied as part of the Common language runtime which is also called as (CLR), and they are integrated into .NET Custom attributes are attributes that you create according to your requirement.

Quick Note: Taking the Nonsense out of looking for the right spyware remover

If you really want to take the work out of looking for that right Spyware Protection from a go to the Internet and get a or a Free
Download, In order to prevent your vital information from being ripped from your computer get your Remover Today.

Some commonly used predefined attributes provided with .NET Framework are conditional, WebMethod, DIIIport and Obsolete. Conditional cause's conditional compilation of method calls, depending on the specified value such as Debug or Trace. It displays the values of variables, when debugging a code. However, this attribute only determines the action that will occur when a method is called. If conditional compilation of a method is required, the statements such as #if and #end if directives are used in code.

Top Searches on
Computers
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 
 • 

» More on Computers