欢迎光临

木子屋

标题: AssemblyInfo.cs信息读取类

作者: dnawo

日期: 2011-05-27 04:03 PM

分类: Win编程

内容: 将以下代码粘贴到AssemblyInfo.cs文件中：
复制内容到剪贴板 程序代码public static class AssemblyInfo
{
/// <summary>
/// 程序集标题
/// </summary>
public static string Title
{
get
{
AssemblyTitleAttribute attribute = getAttribute<AssemblyTitleAttribute>();
return attribute == null ? "" : attribute.Title;
}
}
/// <summary>
/// 产品名称
/// </summary>
public static string Product
{
get
{
AssemblyProductAttribute attribute = getAttribute<AssemblyProductAttribute>();
return attribute == null ? "" : attribute.Product;
}
}
/// <summary>
/// 公司名称
/// </summary>
public static string Company
{
get
{
AssemblyCompanyAttribute attribute = getAttribute<AssemblyCompanyAttribute>();
return attribute == null ? "" : attribute.Company;
}
}
/// <summary>
/// 文本说明
/// </summary>
public static string Description
{
get
{
AssemblyDescriptionAttribute attribute = getAttribute<AssemblyDescriptionAttribute>();
return attribute == null ? "" : attribute.Description;
}
}
/// <summary>
/// 版权
/// </summary>
public static string Copyright
{
get
{
AssemblyCopyrightAttribute attribute = getAttribute<AssemblyCopyrightAttribute>();
return attribute == null ? "" : attribute.Copyright;
}
}
/// <summary>
/// 主版本号、次版本号、内部版本号和修订号
/// </summary>
public static string Version
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
/// <summary>
/// 主版本号
/// </summary>
public static int Major
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.Major;
}
}
/// <summary>
/// 次版本号
/// </summary>
public static int Minor
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.Minor;
}
}
/// <summary>
/// 程序集的简单名称
/// </summary>
public static string Name
{
get
{
return Assembly.GetExecutingAssembly().GetName().Name;
}
}
/// <summary>
/// getAttribute
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
private static T getAttribute<T>() where T : System.Attribute
{
T attribute;
object[] objects = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(T), false);
if (objects.Length > 0)
if ((attribute = objects[0] as T) != null)
return attribute;
return null;
}
}
调用示例：
复制内容到剪贴板 程序代码MessageBox.Show(AssemblyInfo.Product);
--------------------------------------------------------------------------------------------
2014-07-18补充：AssemblyCompany、AssemblyProduct和AssemblyFileVersion可分别用Application.ProductName、Application.CompanyName和Application.ProductVersion获取。

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.772 ms

返回

标题: AssemblyInfo.cs信息读取类

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.772 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 0.803 ms

返回