大多数程序集属性(这通常在在Assembly.cs定义的)可以使用Assembly.GetCustomAttributes.
例如你可以使用如下代码得到程序集标题:
Assembly asm=this.GetType().Assembly;
Object[]attrs=asm.GetCustomAttributes(
typeof(AssemblyTitleAttributes), false));
If(attrs.Length==1)
{
Console.WriteLine(((AssemblyTitleAttributes)attrs[0].Title);
}
注意,AssemblyVersionAttributes最终成为程序集名称(assembly
name)的一部分,程序集名称可以通过Assembly.GetName
方法获取。版本号可以通过名称(name)的版本(Version)属性获取。例如:
Assembly asm=this.GetType().Assembly;
Console.WriteLine(asm.GetName().Version);
相关帖子:
反射和用户属性
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/6d8dc53d-9238-4387-997f-46013e5fa99b/
用什么方法可以得到一个c#类里面存在的属性(Attributes)列表?
http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/16583130-d700-4eb9-9979-d5c955efd899/
如果您对我们的论坛在线支持服务有任何的意见或建议,请通过
邮件告诉我们。