Readable Chapter comparison
This commit is contained in:
parent
7ff9ac53ee
commit
5980b64caa
@ -58,29 +58,24 @@ public readonly struct Chapter : IComparable
|
|||||||
|
|
||||||
public int CompareTo(object? obj)
|
public int CompareTo(object? obj)
|
||||||
{
|
{
|
||||||
if (obj is Chapter otherChapter)
|
if(obj is not Chapter otherChapter)
|
||||||
|
throw new ArgumentException($"{obj} can not be compared to {this}");
|
||||||
|
|
||||||
|
if (float.TryParse(volumeNumber, GlobalBase.numberFormatDecimalPoint, out float volumeNumberFloat) &&
|
||||||
|
float.TryParse(chapterNumber, GlobalBase.numberFormatDecimalPoint, out float chapterNumberFloat) &&
|
||||||
|
float.TryParse(otherChapter.volumeNumber, GlobalBase.numberFormatDecimalPoint,
|
||||||
|
out float otherVolumeNumberFloat) &&
|
||||||
|
float.TryParse(otherChapter.chapterNumber, GlobalBase.numberFormatDecimalPoint,
|
||||||
|
out float otherChapterNumberFloat))
|
||||||
{
|
{
|
||||||
if (float.TryParse(volumeNumber, GlobalBase.numberFormatDecimalPoint, out float volumeNumberFloat) &&
|
return volumeNumberFloat.CompareTo(otherVolumeNumberFloat) switch
|
||||||
float.TryParse(chapterNumber, GlobalBase.numberFormatDecimalPoint, out float chapterNumberFloat) &&
|
|
||||||
float.TryParse(otherChapter.volumeNumber, GlobalBase.numberFormatDecimalPoint,
|
|
||||||
out float otherVolumeNumberFloat) &&
|
|
||||||
float.TryParse(otherChapter.chapterNumber, GlobalBase.numberFormatDecimalPoint,
|
|
||||||
out float otherChapterNumberFloat))
|
|
||||||
{
|
{
|
||||||
|
<0 => -1,
|
||||||
switch (volumeNumberFloat.CompareTo(otherVolumeNumberFloat))
|
>0 => 1,
|
||||||
{
|
_ => chapterNumberFloat.CompareTo(otherChapterNumberFloat)
|
||||||
case < 0:
|
};
|
||||||
return -1;
|
|
||||||
case > 0:
|
|
||||||
return 1;
|
|
||||||
default:
|
|
||||||
return chapterNumberFloat.CompareTo(otherChapterNumberFloat);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else throw new FormatException($"Value could not be parsed");
|
|
||||||
}
|
}
|
||||||
throw new ArgumentException($"{obj} can not be compared to {this}");
|
else throw new FormatException($"Value could not be parsed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user