最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501
当前位置: 首页 - 科技 - 知识百科 - 正文

.net 读取项目AssemblyInfo.cs属性值

来源:懂视网 责编:小采 时间:2020-11-27 22:44:20
文档

.net 读取项目AssemblyInfo.cs属性值

.net 读取项目AssemblyInfo.cs属性值:We write all those code repetitively for dynamic assembly loading and checking to verify few properties on assemblies. It would be a great stop to write all such things in the assemblyinfo.cs (because it needs to completely describe the ass
推荐度:
导读.net 读取项目AssemblyInfo.cs属性值:We write all those code repetitively for dynamic assembly loading and checking to verify few properties on assemblies. It would be a great stop to write all such things in the assemblyinfo.cs (because it needs to completely describe the ass

We write all those code repetitively for dynamic assembly loading and checking to verify few properties on assemblies. It would be a great stop to write all such things in the assemblyinfo.cs (because it needs to completely describe the assembly that it is intended to serve for) You can define your About form of the application entirely using the AssemblyInfo.cs
How to use the following info:
AssemblyInfo ainfo = new AssemblyInfo();
frmAbout.Text = ainfo.Title;
frmAbout.menuAbt.Text = string.Format("&About{0}..",ainfo.Title);
frmAbout.Text = "About " + this.Owner.Text;
frmAbout.Icon = this.Owner.Icon;
//You can set the icon like this on the abt form.
frmAbout.pictureBox1.Image = this.Owner.Icon.ToBitmap();
frmAbout.lblTitle.Text = ainfo.Title;
frmAbout.lblVersion.Text = ainfo.Version;
frmAbout.lblCopyright.Text = ainfo.Copyright;
frmAbout.lblDescription.Text = ainfo.Description;
frmAbout.lblCodebase.Text = ainfo.CodeBase; 
下面是具体的实现代码。
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
[assembly: AssemblyTitle("Demo Title")]
[assembly: AssemblyDescription("Demo app that reads from the Assembly Info file description")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("World Company")]
[assembly: AssemblyProduct("Not for commercial use.")]
[assembly: AssemblyCopyright("open source (US)")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: CLSCompliant(true)]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]
//
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.1.1")]
# region "Class to get the information for AboutForm"
/* This class uses the System.Reflection.Assembly class to access assembly meta-data.
* This class is not a normal feature of AssmblyInfo.cs */
/// <summary>
/// AssemblyInfo class.
/// </summary>
public class AssemblyInfo
{
//Used by functions to access information from Assembly Attributes
/// <summary>
/// myType.
/// </summary>
private Type myType;
/// <summary>
/// Initializes a new instance of the <see cref="AssemblyInfo"/> class.
/// </summary>
public AssemblyInfo()
{
//Shellform here denotes the actual form.
myType = typeof(ShellForm);
}
/// <summary>
/// Gets the name of the assembly.
/// </summary>
/// <value>The name of the assembly.</value>
public String AssemblyName
{
get
{
return myType.Assembly.GetName().Name.ToString();
}
}
/// <summary>
/// Gets the full name of the assembly.
/// </summary>
/// <value>The full name of the assembly.</value>
public String AssemblyFullName
{
get
{
return myType.Assembly.GetName().FullName.ToString();
}
}
/// <summary>
/// Gets the code base.
/// </summary>
/// <value>The code base.</value>
public String CodeBase
{
get
{
return myType.Assembly.CodeBase;
}
}
/// <summary>
/// Gets the copyright.
/// </summary>
/// <value>The copyright.</value>
public String Copyright
{
get
{
Type att = typeof(AssemblyCopyrightAttribute);
object[] r = myType.Assembly.GetCustomAttributes(att, false);
AssemblyCopyrightAttribute copyattr = (AssemblyCopyrightAttribute)r[0];
return copyattr.Copyright;
}
}
/// <summary>
/// Gets the company.
/// </summary>
/// <value>The company.</value>
public String Company
{
get
{
Type att = typeof(AssemblyCompanyAttribute);
object[] r = myType.Assembly.GetCustomAttributes(att, false);
AssemblyCompanyAttribute compattr = (AssemblyCompanyAttribute)r[0];
return compattr.Company;
}
}
/// <summary>
/// Gets the description.
/// </summary>
/// <value>The description.</value>
public String Description
{
get
{
Type att = typeof(AssemblyDescriptionAttribute);
object[] r = myType.Assembly.GetCustomAttributes(att, false);
AssemblyDescriptionAttribute descattr = (AssemblyDescriptionAttribute)r[0];
return descattr.Description;
}
}
/// <summary>
/// Gets the product.
/// </summary>
/// <value>The product.</value>
public String Product
{
get
{
Type att = typeof(AssemblyProductAttribute);
object[] r = myType.Assembly.GetCustomAttributes(att, false);
AssemblyProductAttribute prodattr = (AssemblyProductAttribute)r[0];
return prodattr.Product;
}
}
/// <summary>
/// Gets the title.
/// </summary>
/// <value>The title.</value>
public String Title
{
get
{
Type att = typeof(AssemblyTitleAttribute);
object[] r = myType.Assembly.GetCustomAttributes(att, false);
AssemblyTitleAttribute titleattr = (AssemblyTitleAttribute)r[0];
return titleattr.Title;
}
}
/// <summary>
/// Gets the version.
/// </summary>
/// <value>The version.</value>
public String Version
{
get
{
return myType.Assembly.GetName().Version.ToString();
}
}
}
# endregion

声明:本网页内容旨在传播知识,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文档

.net 读取项目AssemblyInfo.cs属性值

.net 读取项目AssemblyInfo.cs属性值:We write all those code repetitively for dynamic assembly loading and checking to verify few properties on assemblies. It would be a great stop to write all such things in the assemblyinfo.cs (because it needs to completely describe the ass
推荐度:
标签: 获取 项目 net
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top