friendsterTalk - Friendster Forum

friendsterTalk - Friendster Forum

Welcome guest! Please Login or Register.

#1  2008-11-11 17:19:46

creamownedz
 active server protocol
creamownedz's display avatar
» FriendsterTalker
PsychoCoder
Class-S
Location: Ftalk & MCTF
Registered: 2008-03-22
Posts: 115
Last visit: Yesterday
Reputation: 7

Retrieve the version number of a component [c#]

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.


Code:

//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;
}

...Giving of reputation are highly appreciating for me...
Computers don't make errors what they do they do on purpose
...computer is my expertise...
....an addicted coder....
....don't ripp all my tutorials....

Search Friendstertalk

Board footer

FriendsterTalk is not affiliated with Friendster.com
Copyright © 2002–2009 PunBB

[ 8 queries - 2.523 second ]

Pay Per Click Ads by pay per click advertising by Kontera

FriendsterTalk.com x

Welcome to FriendsterTalk! You'll need to login in order to fully use all the features and view all the sections of this site.

Please register if you're not yet a member. =)