blog

Home / DeveloperSection / Blogs / Attributes & Reflection

Attributes & Reflection

Chris Anderson5914 09-Aug-2011

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.

Attributes:

An attribute is declarative tag that is used to convey information to runtime about the behavior of programmatic elements such as classes, assemblies.

There are various predefined attributes in .Net. You can create your own attribute by using System.Attribute namespace.

The following syntax enables you to specify an attribute:

 [attribute (positional_parameters, name_parameter=value, ….)]

 element


Reflection:

Reflection is used in the process of obtaining type information at runtime.

System.Reflection namespace.Reflection provides objects that encapsulate

assemblies, modules, and types.

The classes that give access to the metadata of a running program are in


// dynamically load assembly from file Test.dll
Assembly testAssembly = Assembly.LoadFile(@"c:\Test.dll");
// get type of class Calculator from just loaded assembly
Type calcType = testAssembly.GetType("Test.Calculator");

 


Updated 18-Sep-2014
hi I am software developer at mindstick software pvt. ltd.

Leave Comment

Comments

Liked By