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");
Anonymous User
19-Apr-2019Thank You for sharing.
Anurag Sharma
27-Aug-2011Anurag Sharma
27-Aug-2011