-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAssemblyVersion.cs
206 lines (185 loc) · 6.92 KB
/
AssemblyVersion.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Reflection;
namespace genBTC.FileTime
{
/// <summary>
/// This class uses the System.Reflection.Assembly class to
/// access assembly meta-data
/// </summary>
public class AssemblyVersion
{
#region Constructor...
// Used by Helper Functions to access information from Assembly Attributes
private readonly Type assemblyType;
/// <summary>
/// Constructor
/// </summary>
public AssemblyVersion()
{
assemblyType = GetType();
}
#endregion Constructor...
#region Assembly Attributes...
/// <summary>
/// Describes an assembly's unique identity in full.
/// </summary>
public string AssemblyName
{
get { return assemblyType.Assembly.GetName().Name; }
}
/// <summary>
/// Gets the full name of the assembly, also known as the display name.
/// </summary>
public string AssemblyFullName
{
get { return assemblyType.Assembly.GetName().FullName; }
}
/// <summary>
/// Gets the location of the assembly as specified originally, for example, in an AssemblyName object.
/// </summary>
public string CodeBase
{
get { return assemblyType.Assembly.CodeBase; }
}
/// <summary>
/// Defines a copyright custom attribute for an assembly manifest.
/// </summary>
public string Copyright
{
get
{
var at = typeof(AssemblyCopyrightAttribute);
var r = assemblyType.Assembly.GetCustomAttributes(at, false);
var ct = (AssemblyCopyrightAttribute)r[0];
return ct.Copyright;
}
}
/// <summary>
/// Defines a company name custom attribute for an assembly manifest.
/// </summary>
public string Company
{
get
{
var at = typeof(AssemblyCompanyAttribute);
var r = assemblyType.Assembly.GetCustomAttributes(at, false);
var ct = (AssemblyCompanyAttribute)r[0];
return ct.Company;
}
}
/// <summary>
/// Defines an assembly description custom attribute for an assembly manifest.
/// </summary>
public string Description
{
get
{
var at = typeof(AssemblyDescriptionAttribute);
var r = assemblyType.Assembly.GetCustomAttributes(at, false);
var da = (AssemblyDescriptionAttribute)r[0];
return da.Description;
}
}
/// <summary>
/// Defines a product name custom attribute for an assembly manifest.
/// </summary>
public string Product
{
get
{
var at = typeof(AssemblyProductAttribute);
var r = assemblyType.Assembly.GetCustomAttributes(at, false);
var pt = (AssemblyProductAttribute)r[0];
return pt.Product;
}
}
/// <summary>
/// Defines an assembly title custom attribute for an assembly manifest.
/// </summary>
public string Title
{
get
{
var at = typeof(AssemblyTitleAttribute);
var r = assemblyType.Assembly.GetCustomAttributes(at, false);
var ta = (AssemblyTitleAttribute)r[0];
return ta.Title;
}
}
/// <summary>
/// Defines a trademark custom attribute for an assembly manifest.
/// </summary>
public string Trademark
{
get
{
var at = typeof(AssemblyTrademarkAttribute);
var r = assemblyType.Assembly.GetCustomAttributes(at, false);
var ta = (AssemblyTrademarkAttribute)r[0];
return ta.Trademark;
}
}
/// <summary>
/// Gets the major, minor, revision, and build numbers of the assembly.
/// </summary>
public string Version
{
get { return assemblyType.Assembly.GetName().Version.ToString(); }
}
/// <summary>
/// Gets the major, minor, revision, and build numbers of the assembly.
/// </summary>
public string VersionDetails
{
get
{
return assemblyType.Assembly.GetName().Version.Major + "." +
assemblyType.Assembly.GetName().Version.Minor + " (Build: " +
assemblyType.Assembly.GetName().Version.Build + ") (Revision: " +
assemblyType.Assembly.GetName().Version.Revision + ")";
}
}
#endregion Assembly Attributes...
#region Display Functions...
/// <summary>
/// Returns a string with the assembly version attributes
/// </summary>
/// <returns>String with the assembly version attributes</returns>
public override string ToString()
{
string str;
str = "Title: " + Title + "\r\n\r\n";
str += "Assembly Name: " + AssemblyName + "\r\n\r\n";
str += "Assembly Full Name: " + AssemblyFullName + "\r\n\r\n";
str += "CodeBase: " + CodeBase + "\r\n\r\n";
str += "Copyright: " + Copyright + "\r\n\r\n";
str += "Company: " + Company + "\r\n\r\n";
str += "Description: " + Description + "\r\n\r\n";
str += "Product: " + Product + "\r\n\r\n";
str += "Version: " + Version + "\r\n\r\n";
str += "Version: " + VersionDetails + "\r\n\r\n";
return str;
}
/// <summary>
/// Returns a HTML format string with the assembly version attributes
/// </summary>
/// <returns>HTML format string with the assembly version attributes</returns>
public string ToHTML()
{
string str;
str = "<b>Title: " + Title + "</b><P></P>";
str += "<li><b>Assembly Name: </b>" + AssemblyName;
str += "<li><b>Assembly Full Name: </b>" + AssemblyFullName;
str += "<li><b>CodeBase: </b>" + CodeBase;
str += "<li><b>Copyright: </b>" + Copyright;
str += "<li><b>Company: </b>" + Company;
str += "<li><b>Description: </b>" + Description;
str += "<li><b>Product: </b>" + Product;
str += "<li><b>Trademark: </b>" + Trademark;
str += "<li><b>Version: </b>" + Version;
str += "<li><b>Version: </b>" + VersionDetails;
return str;
}
#endregion Display Functions...
}
}