时间:2021-05-28
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
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
AssemblyInfo.cs文件:包含程序版本、信息、版权的属性文件 先介绍AssemblyInfo.cs文件中的程序集属性 内容:usingSyst
如下XML文件:(算是一个属性值比较多的xml文件。。。读取该Xml算是我在公司实际的一个任务)创建一个类WriteXml用来封装读取Xml的和属性值方法:代码
数据属性:数据属性包含一个数据值的位置,在这个位置可以读取和写入值。4个描述的行为特性:writable表示能否修改属性的值。默认为trueEnumerable
一、考虑安全访问范围内的属性,没有权限访问到的属性不读取/***根据属性名获取属性值**@paramfieldName*@paramobject*@return
本文源码下载:http://xiazai.jb51.net/201501/tools/cs-key-setting.rar项目开发过程中,需要实现类似有道词典的