“Reflection is a collection of classs”
“system.refelection is namespace used to get name information about the assembly”
Reflection is the ability of the .NET framework to gather information (metadata) about assemblies, modules and types at runtime. It allows you also to dynamically create instances of types, invoke methods and access fields, properties and attributes.
Reflection
- Ability to read metadata at runtime.
- Using reflection, it is possible to uncover the methods, properties, and events of a type, and to invoke them dynamically.
- Create new types at runtime.
- Derived from namespace System.Reflection.
Example
Get the Version of the assembly
First add the reflection namespace
using System.Reflection;
Example 1
// get the version object for this assembly
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
// write out the whole version number
Response.Write("Version = " + v.ToString());Output
Output
Version = 0.0.0.0
Example 2
Add assembly version attribute
using System.Reflection;
[assembly: AssemblyVersionAttribute("1.2.3.4")]
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// get the version object for this assembly
Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
// write out the whole version number
Response.Write("Version = " + v.ToString());
}
}
Output
Version = 1.2.3.4
Comments
Post a Comment