blob: bad90d47f05101c1675af508caac03cedaa88c4b (
plain)
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
public static class AssemblyExtensions
{
/// <summary>
/// Gets the assembly build date according to the visual studio extension (auto version increment).
/// The scheme of the assembly version should be {Major}.{Minor}.{BuildNumber}.{YYDDD}
/// The revision number contains the number of years since 2000 and day in year.
/// </summary>
/// <param name="asm">The assembly.</param>
/// <returns></returns>
public static DateTime GetBuildDate(this Assembly asm)
{
var version = asm.GetName().Version;
String revision = version.Revision.ToString();
if (revision.Length == 5)
{
int years = int.Parse(new String(revision.Take(2).ToArray()));
int day = int.Parse(new String(revision.Skip(2).ToArray()));
return new DateTime(2000, 1, 1).AddYears(years).AddDays(day - 1);
}
else
{
return new DateTime(2000, 1, 1)
.AddDays(version.Revision);
}
}
public static IEnumerable<Type> GetLoadableTypes(this Assembly assembly)
{
try
{
return assembly.GetTypes();
}
catch (ReflectionTypeLoadException e)
{
return e.Types.Where(t => t != null);
}
}
}
|