Home > DeveloperSection > Blogs > Attributes & Reflection

Attributes & Reflection


.NET .NET 
Ratings:
2 Comment(s)
 3762  View(s)
Rate this:

Attributes & Reflection

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.
The classes that give access to the metadata of a running program are in
System.Reflection namespace.
Reflection provides objects that encapsulate assemblies, modules, and types.

// 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");

 


Attributes & Reflection

By Anurag Sharma on   5 years ago
nice blog..

Attributes & Reflection

By Anurag Sharma on   5 years ago
Thanks

Don't want to miss updates? Please click the below button!

Follow MindStick