Following C# class can be reused to get Information about Application Name, Version, Product, Copyright Information, etc. The code uses the Assemblyinfo.cs file settings to retrieve the required information.
using System;
using System.Reflection;
namespace Reuse
{
/// <summary>
/// Summary description for clsAssembly.
/// </summary>
public class KAssembly
{
public KAssembly()
{
//
// TODO: Add constructor logic here
//
}
public static string GetName()
{
return Assembly.GetEntryAssembly().GetName().Name;
}
public static string GetVersion()
{
return Assembly.GetEntryAssembly().GetName().Version.ToString();
}
public static string GetProduct()
{
object[] attrs = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute),false);
return ((AssemblyProductAttribute) attrs[0]).Product;
}
public static string GetCopyright()
{
object[] attrs = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute),false);
return ((AssemblyCopyrightAttribute) attrs[0]).Copyright;
}
}
}
using System;
using System.Reflection;
namespace Reuse
{
/// <summary>
/// Summary description for clsAssembly.
/// </summary>
public class KAssembly
{
public KAssembly()
{
//
// TODO: Add constructor logic here
//
}
public static string GetName()
{
return Assembly.GetEntryAssembly().GetName().Name;
}
public static string GetVersion()
{
return Assembly.GetEntryAssembly().GetName().Version.ToString();
}
public static string GetProduct()
{
object[] attrs = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute),false);
return ((AssemblyProductAttribute) attrs[0]).Product;
}
public static string GetCopyright()
{
object[] attrs = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute),false);
return ((AssemblyCopyrightAttribute) attrs[0]).Copyright;
}
}
}
No comments:
Post a Comment