C# 窗口项目中文件架构分析(一)

今天重温C#,认认真真的研究了一下项目里面的各种文件,终于大体摸清了他们到底是干什么用的了,嘿嘿,以前光低着头做,可是没好好研究研究微软的项目习惯。

 

AssemblyInfo.cs文件:包含程序版本、信息、版权的属性文件

先介绍AssemblyInfo.cs文件中的程序集属性

 

内容:

using System.Reflection;
using System.Runtime.CompilerServices;


[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

其意义如下:
1. [assembly: AssemblyTitle("")]

[assembly: AssemblyTitle("")]代码中”:”好前面的assembly表示此属性在程序集范围内发生作用。
类型名:System.Reflection.AssemblyTitleAttribute
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyTitleAttribute : Attribute

此属性描述程序集的名称,如:某某公司某某项目某某模块等,此名称可以是任何合法的字符串,可以有空格。


2. [assembly: AssemblyDescription("")]
类型名:
System.Reflection.AssemblyDescriptionAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyDescriptionAttribute : Attribute

功能:
程序集的简单描述,如功能、语言等

3. [assembly: AssemblyDescription("")]
类型名:
System.Reflection.AssemblyDescriptionAttribute


Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyDescriptionAttribute : Attribute
功能:
程序集的简单说明,描述程序集的功能、特性、约束等


4. [assembly: AssemblyConfiguration("")]
类型名:
System.Reflection.AssemblyConfigurationAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyConfigurationAttribute : Attribute
功能:
程序集的配置信息,如:零售、发布、调试等,.NET运行时没有使用此属性

5. [assembly: AssemblyCompany("")]
类型名:
System.Reflection.AssemblyCompanyAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyCompanyAttribute : Attribute
功能:
程序集所属的公司名称

6. [assembly: AssemblyProduct("")]
类型名:
System.Reflection.AssemblyProductAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyProductAttribute : Attribute
功能:
程序集所述的产品名

7. [assembly: AssemblyCopyright("")]
类型名:
System.Reflection.AssemblyCopyrightAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyCopyrightAttribute : Attribute
功能:
程序集的版权信息

8. [assembly: AssemblyTrademark("")]
类型名:
System.Reflection.AssemblyTrademarkAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyTrademarkAttribute : Attribute
功能:
程序集的商标信息

9. [assembly: AssemblyCulture("")]
类型名:
System.Reflection.AssemblyCultureAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyCultureAttribute : Attribute
功能:
枚举的字段表明程序集支持的区域性。程序集也可以指定区域独立性,表明它包含用于默认区域性的资源。运行库将任何区域性属性未设为空的程序集按附属程序集处理。此类程序集受附属程序集绑定规则约束。详细信息,请参见运行库如何定位程序集。

10. [assembly: AssemblyVersion("")]
类型名:
System.Reflection.AssemblyVersionAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyVersionAttribute : Attribute
功能:
程序集版本信息,按照4段式保存版本信息,即:主.次要.内部版本.修改版本。在强名称程序集中CLR使用此值来绑定操作。可以使用通配符*来替代内部版本和修改版本,VS将自动为其生成版本号。如定义为“1.0.*”,则VS会自动生成后面的部分。如果设定为*,则每次修改程序后版本号都会自动发生变更。

11. [assembly: AssemblyDelaySign(false)]
类型名:
System.Reflection.AssemblyDelaySignAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyDelaySignAttribute : Attribute
功能:
是否使用延迟签名

12. [assembly: AssemblyKeyFile("")]
类型名:
System.Reflection.AssemblyKeyFileAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyKeyFileAttribute : Attribute
功能:
包含了公钥(如果使用延迟签名)或者既包含公钥也包含私钥的文件名。此公钥和私钥将作为参数传递至此属性的构造函数。文件名称与输出文件路径(.exe 或 .dll)相关,与源文件路径无关。
13. [assembly: AssemblyKeyName("")]
类型名:
System.Reflection.AssemblyKeyNameAttribute
Attribute声明:
[AttributeUsage(AttributeTargets.Assembly)]
public sealed class AssemblyKeyNameAttribute : Attribute
功能:
表明包含密钥对(作为参数传递至此属性的构造函数)的密钥容器。

 

 那么怎么读取这些文件信息呢?
可以采用以下方法:

 object[] att = assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
     string title = ((AssemblyDescriptionAttribute)att[0]).Description;
     System.Windows.Forms.MessageBox.Show(title.ToString());

其中,可以通过改变typeof中的参数访问不同的属性,注意要将att的类型进行对应的类型转换。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值