/// <summary> /// Creates a new version number /// </summary> /// <returns>The version number</returns> public static Version CreateVersion(VersionNumberFormat format, VersionType type) { var year = DateTime.Now.ToString("yy").ToInt(); var week = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstDay, DayOfWeek.Monday); var daysOfYear = DateTime.Now.DayOfYear; var minuteOfDay = (int)DateTime.Now.TimeOfDay.TotalMinutes; switch (format) { case VersionNumberFormat.Short: return(type == VersionType.WithCalendarWeek ? new Version(year, week) : new Version(year, daysOfYear)); case VersionNumberFormat.Middle: return(type == VersionType.WithCalendarWeek ? new Version(year, week, 0) : new Version(year, daysOfYear, 0)); default: return(type == VersionType.WithCalendarWeek ? new Version(year, week, 0, minuteOfDay) : new Version(year, daysOfYear, 0, minuteOfDay)); } }
/// <summary> /// Gets the desired version string /// </summary> /// <param name="version">The version</param> /// <param name="format">The version format</param> /// <returns>The formatted version</returns> public static string GetVersionString(Version version, VersionNumberFormat format) { switch (format) { case VersionNumberFormat.Short: return($"{version.Major}.{version.Minor}"); case VersionNumberFormat.Middle: return($"{version.Major}.{version.Minor}.{version.Build}"); default: return(version.ToString()); } }