
Retrieve the version number of a component
Instructions: Pass the method the component (Type) you wish to retrieve the version of, it will return a HashTable populated with your key/value pairs.
//Namespace Reference
using System;
using System.Reflection;
/// <summary>
/// method to retrieve the version of a specified component
/// using reflection
/// </summary>
/// <param name="type">
/// Component to retrieve the version for
/// </param>
/// <returns></returns>
public Hashtable RetrieveComponentVersion(Type type)
{
//HashTable instance to hold version number
Hashtable version = new Hashtable();
try
{
type = Type.GetType("System.Int32");
//retrieve the component (type)
Assembly assembly = Assembly.GetAssembly(type);
//get the name of the assembly (component)
AssemblyName name = assembly.GetName();
//create an instance of the Version object
Version ver = name.Version;
//now add version info to HashTable
version.Add("Component: ",name);
version.Add("Version: ", ver);
version.Add("Major: ", ver.Major);
version.Add("Minor: ", ver.Minor);
version.Add("Build: ", ver.Build);
version.Add("Revision: ", ver.Revision);
}
catch(ReflectionTypeLoadException ex)
{
version=null;
MessageBox.Show(ex.Message);
}
catch(Exception ex)
{
version=null;
MessageBox.Show(ex.Message);
}
return version;
}-Offline- |