C#反射之获取程序集信息
先贴代码,再写文字……
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using System;
2 using System.Reflection;
3
4 namespace Dxy.ReflectionTest
5 {
6 public class AssemblyInfoHelper
7 {
8 Type m_Type;
9 public AssemblyInfoHelper(Type type)
10 {
11 this.m_Type = type;
12 Assembly assembly = Assembly.GetAssembly(type);
13 VersionInfo = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)[0] as AssemblyFileVersionAttribute;
14 CompanyInfo = assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false)[0] as AssemblyCompanyAttribute;
15 ProductInfo = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false)[0] as AssemblyProductAttribute;
16 TitleInfo = assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false)[0] as AssemblyTitleAttribute;
17 CopyrightInfo = assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false)[0] as AssemblyCopyrightAttribute;
18 DescriptionInfo = assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)[0] as AssemblyDescriptionAttribute;
19 }
20 /// <summary>
21 /// 版本信息
22 /// </summary>
23 public AssemblyFileVersionAttribute VersionInfo
24 {
25 get;
26 private set;
27 }
28 /// <summary>
29 /// 公司信息
30 /// </summary>
31 public AssemblyCompanyAttribute CompanyInfo
32 {
33 get;
34 private set;
35 }
36 /// <summary>
37 /// 产品信息
38 /// </summary>
39 public AssemblyProductAttribute ProductInfo
40 {
41 get;
42 private set;
43 }
44 /// <summary>
45 /// 标题信息
46 /// </summary>
47 public AssemblyTitleAttribute TitleInfo
48 {
49 get;
50 private set;
51 }
52 /// <summary>
53 /// 版权信息
54 /// </summary>
55 public AssemblyCopyrightAttribute CopyrightInfo
56 {
57 get;
58 private set;
59 }
60 /// <summary>
61 /// 描述信息
62 /// </summary>
63 public AssemblyDescriptionAttribute DescriptionInfo
64 {
65 get;
66 private set;
67 }
68
69 }
70 }
71
懒惰,是一个通病。
努力,必会成为一种习惯。