[C#] 常用工具类——应用程序属性信息访问类

using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace Utils
{
/// <summary>
/// <para> </para>
///  常用工具类——应用程序属性信息访问类
/// <para> -------------------------------------------</para>
/// <para> GetAssemblyTitle:获取应用程序集的标题</para>
/// <para> GetAssemblyProduct:获取应用程序产品名称</para>
/// <para> GetAssemblyVersion:获取应用程序版本</para>
/// <para> GetAssemblyDescription:获取应用程序说明</para>
/// <para> GetAssemblyCopyright:获取应用程序版权信息</para>
/// <para> GetAssemblyCompany:获取应用程序公司名称</para>
/// <para> GetAssemblyAppFullName:获取应用程序显示名称</para>
/// </summary>
public class AssemblyHelper
{
#region 获取应用程序集的标题
/// <summary>
/// 获取应用程序集的标题
/// </summary>
/// <returns></returns>
public static string GetAssemblyTitle()
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
if (attributes.Length > 0)
{
AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
if (titleAttribute.Title != "")
{
return titleAttribute.Title;
}
}
return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}
#endregion
#region 获取应用程序产品名称
/// <summary>
/// 获取应用程序产品名称
/// </summary>
/// <returns></returns>
public static string GetAssemblyProduct()
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyProductAttribute)attributes[0]).Product;
}
#endregion
#region 获取应用程序版本
/// <summary>
/// 获取应用程序版本
/// </summary>
/// <returns></returns>
public static string GetAssemblyVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
#endregion
#region 获取应用程序说明
/// <summary>
/// 获取应用程序说明
/// </summary>
/// <returns></returns>
public static string GetAssemblyDescription()
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyDescriptionAttribute)attributes[0]).Description;
}
#endregion
#region 获取应用程序版权信息
/// <summary>
/// 获取应用程序版权信息
/// </summary>
/// <returns></returns>
public static string GetAssemblyCopyright()
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}
#endregion
#region 获取应用程序公司名称
/// <summary>
/// 获取应用程序公司名称
/// </summary>
/// <returns></returns>
public static string GetAssemblyCompany()
{
object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length == 0)
{
return "";
}
return ((AssemblyCompanyAttribute)attributes[0]).Company;
}
#endregion
#region 获取应用程序显示名称
/// <summary>
/// 获取应用程序显示名称
/// </summary>
/// <returns></returns>
public static string GetAssemblyAppFullName()
{
return Assembly.GetExecutingAssembly().FullName.ToString();
}
#endregion
}
}

  

上一篇:TOML简介 (转) TOML的由来


下一篇:UNIX网络编程——send与recv函数详解