Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions IntelliTect.Multitool/ReleaseDateAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@
namespace IntelliTect.Multitool;

/// <summary>
/// Information about the executing assembly.
/// The release date assembly attribute.
/// </summary>
[AttributeUsage(AttributeTargets.Assembly)]
public class ReleaseDateAttribute : Attribute
{
/// <summary>
/// Constructor called from csproj file
/// Constructor that takes in a DateTime string
/// </summary>
/// <param name="utcDateString">A utc O (round-trip date/time) format string</param>
/// <param name="utcDateString">A DateTime 'O' (round-trip date/time) format string</param>
public ReleaseDateAttribute(string utcDateString)
{
ReleaseDate = DateTime.ParseExact(utcDateString, "O", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
ReleaseDate = DateTime.ParseExact(utcDateString, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind);
}

/// <summary>
/// The date the assembly was built
/// </summary>
public DateTime ReleaseDate { get; }

/// <summary>
/// Method to obtain the release date from the assembly attributes
/// Method to obtain the release date from the assembly attribute
/// </summary>
/// <param name="assembly">An assembly instance</param>
/// <returns>The date time from compilation time</returns>
/// <returns>The date time from the assembly attribute</returns>
public static DateTime? GetReleaseDate(Assembly? assembly = null)
{
object[]? attribute = (assembly ?? Assembly.GetEntryAssembly())?.GetCustomAttributes(typeof(ReleaseDateAttribute), false);
return attribute?.Length >= 1 ? ((ReleaseDateAttribute)attribute[0]).ReleaseDate : null;
}

}