1- using System ;
2- using System . IO ;
3- using System . Reflection ;
1+ using System . Reflection ;
42
5- namespace IntelliTect . Multitool
3+ namespace IntelliTect . Multitool ;
4+
5+ /// <summary>
6+ /// Information about the executing assembly.
7+ /// </summary>
8+ public static class AssemblyInfo
69{
10+ private static DateTime ? _Date ;
11+
712 /// <summary>
8- /// Information about the executing assembly.
13+ /// Gets the linker date from the assembly header .
914 /// </summary>
10- public static class AssemblyInfo
15+ public static DateTime Date
1116 {
12- private static DateTime ? _Date ;
13-
14- /// <summary>
15- /// Gets the linker date from the assembly header.
16- /// </summary>
17- public static DateTime Date
17+ get
1818 {
19- get
19+ if ( _Date == null )
2020 {
21- if ( _Date == null )
22- {
23- _Date = GetLinkerTime ( Assembly . GetExecutingAssembly ( ) ) ;
24- }
25- return _Date . Value ;
21+ _Date = GetLinkerTime ( Assembly . GetExecutingAssembly ( ) ) ;
2622 }
23+ return _Date . Value ;
2724 }
25+ }
2826
29- /// <summary>
30- /// Gets the linker date of the assembly.
31- /// </summary>
32- /// <param name="assembly"></param>
33- /// <returns></returns>
34- /// <remarks>https://blog.codinghorror.com/determining-build-date-the-hard-way/</remarks>
35- private static DateTime GetLinkerTime ( Assembly assembly )
36- {
37- var filePath = assembly . Location ;
38- const int cPeHeaderOffset = 60 ;
39- const int cLinkerTimestampOffset = 8 ;
27+ /// <summary>
28+ /// Gets the linker date of the assembly.
29+ /// </summary>
30+ /// <param name="assembly"></param>
31+ /// <returns></returns>
32+ /// <remarks>https://blog.codinghorror.com/determining-build-date-the-hard-way/</remarks>
33+ private static DateTime GetLinkerTime ( Assembly assembly )
34+ {
35+ var filePath = assembly . Location ;
36+ const int cPeHeaderOffset = 60 ;
37+ const int cLinkerTimestampOffset = 8 ;
4038
41- var buffer = new byte [ 2048 ] ;
39+ var buffer = new byte [ 2048 ] ;
4240
43- using ( var stream = new FileStream ( filePath , FileMode . Open , FileAccess . Read ) )
44- stream . Read ( buffer , 0 , 2048 ) ;
41+ using ( var stream = new FileStream ( filePath , FileMode . Open , FileAccess . Read ) )
42+ stream . Read ( buffer , 0 , 2048 ) ;
4543
46- var offset = BitConverter . ToInt32 ( buffer , cPeHeaderOffset ) ;
47- var secondsSince1970 = BitConverter . ToInt32 ( buffer , offset + cLinkerTimestampOffset ) ;
48- var epoch = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
44+ var offset = BitConverter . ToInt32 ( buffer , cPeHeaderOffset ) ;
45+ var secondsSince1970 = BitConverter . ToInt32 ( buffer , offset + cLinkerTimestampOffset ) ;
46+ var epoch = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
4947
50- var linkTimeUtc = epoch . AddSeconds ( secondsSince1970 ) ;
48+ var linkTimeUtc = epoch . AddSeconds ( secondsSince1970 ) ;
5149
52- return linkTimeUtc ;
53- }
50+ return linkTimeUtc ;
5451 }
5552}
0 commit comments