-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provide a unified impl for progress value
- Loading branch information
1 parent
d0df8a4
commit 89dcaff
Showing
22 changed files
with
144 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
namespace ProjBobcat.Class.Model; | ||
|
||
/// <summary> | ||
/// A unified impl for the progress value | ||
/// <br/> | ||
/// <b>Implicit convert this struct to <seealso cref="double"/> will get the value of <seealso cref="NormalizedValue"/> </b> | ||
/// </summary> | ||
/// <param name="NormalizedValue"></param> | ||
public readonly record struct ProgressValue(double NormalizedValue) : IFormattable | ||
{ | ||
/// <summary> | ||
/// Display value for the progress, range usually in 0-100 | ||
/// </summary> | ||
public double DisplayValue => this.NormalizedValue * 100; | ||
|
||
public static implicit operator double(ProgressValue value) => value.DisplayValue; | ||
|
||
public static ProgressValue Start => new (0); | ||
public static ProgressValue Finished => new (1); | ||
|
||
/// <summary> | ||
/// Create a new progress base on <seealso cref="numerator"/> and <seealso cref="denominator"/> | ||
/// </summary> | ||
/// <param name="numerator"></param> | ||
/// <param name="denominator"></param> | ||
/// <returns></returns> | ||
public static ProgressValue Create(double numerator, double denominator) => FromNormalized(numerator / denominator); | ||
public static ProgressValue FromNormalized(double normalizedValue) => new (normalizedValue); | ||
public static ProgressValue FromDisplay(double displayValue) => new (displayValue / 100); | ||
|
||
public string ToString(string? format, IFormatProvider? formatProvider) | ||
{ | ||
return NormalizedValue.ToString(format, formatProvider); | ||
} | ||
|
||
public override string ToString() => NormalizedValue.ToString(CultureInfo.CurrentCulture); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.