Use Assembly Helper Class to retrieve Information on any assembly

A sample Helper class to retrieve information on any assembly

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.IO;

namespace Utilities
{
    /// <summary>
    ///
    /// </summary>
    class AssemblyHelper
    {
         /// <summary>
        /// Gets the assembly title.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        public static string GetAssemblyTitle(Assembly assembly)
         {
             string title = "";

             if (Attribute.IsDefined(assembly, typeof(AssemblyTitleAttribute)))
            {
                AssemblyTitleAttribute asTitle = (AssemblyTitleAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyTitleAttribute));
                title = asTitle.Title;
             }

             return title;
        }


        /// <summary>
        /// Gets the full name of the assembly.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        public static string GetAssemblyFullName(Assembly assembly)
         {
             string fullName = "";

             if (Attribute.IsDefined(assembly, typeof(AssemblyName)))
            {
                fullName = assembly.FullName;
             }

             return fullName;
        }


        /// <summary>
        /// Gets the name of the product.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        public static string GetProductName(Assembly assembly)
         {
             string productName = "";

             if (Attribute.IsDefined(assembly, typeof(AssemblyProductAttribute)))
            {
                AssemblyProductAttribute asProductName = (AssemblyProductAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyProductAttribute));
                productName = asProductName.Product;
             }

             return productName;
        }


        /// <summary>
        /// Gets the trade mark.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        public static string GetTradeMark(Assembly assembly)
         {
             string tradeMark = "";

             if (Attribute.IsDefined(assembly, typeof(AssemblyTrademarkAttribute)))
            {
                AssemblyTrademarkAttribute asTradeMark = (AssemblyTrademarkAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyTrademarkAttribute));
                tradeMark = asTradeMark.Trademark;
             }

             return tradeMark;
        }

        /// <summary>
        /// Gets the assembly version.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        public static string GetAssemblyVersion(Assembly assembly)
         {
             string version = "";

             if (Attribute.IsDefined(assembly, typeof(AssemblyVersionAttribute)))
            {
                AssemblyVersionAttribute asVersion = (AssemblyVersionAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyVersionAttribute));
                version = asVersion.Version;
             }

             return version;
        }


        /// <summary>
        /// Gets the assembly company.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <returns></returns>
        public static string GetAssemblyCompany(Assembly assembly)
         {
             string company = "";

             if (Attribute.IsDefined(assembly, typeof(AssemblyCompanyAttribute)))
            {
                AssemblyCompanyAttribute ascompany = (AssemblyCompanyAttribute)Attribute.GetCustomAttribute(assembly, typeof(AssemblyCompanyAttribute));
                company =  ascompany.Company;
             }

             return company;
        }

           }
}
By [)ia6l0 iii   Popularity  (1449 Views)