Merge branch 'refs/heads/cuttingedge-merge-ServerV2' into cuttingedge

This commit is contained in:
Glax 2024-09-11 14:41:35 +02:00
commit a94186455b

View File

@ -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))
{
switch (volumeNumberFloat.CompareTo(otherVolumeNumberFloat)) if (float.TryParse(volumeNumber, GlobalBase.numberFormatDecimalPoint, out float volumeNumberFloat) &&
{ float.TryParse(chapterNumber, GlobalBase.numberFormatDecimalPoint, out float chapterNumberFloat) &&
case < 0: float.TryParse(otherChapter.volumeNumber, GlobalBase.numberFormatDecimalPoint,
return -1; out float otherVolumeNumberFloat) &&
case > 0: float.TryParse(otherChapter.chapterNumber, GlobalBase.numberFormatDecimalPoint,
return 1; out float otherChapterNumberFloat))
default: {
return chapterNumberFloat.CompareTo(otherChapterNumberFloat); return volumeNumberFloat.CompareTo(otherVolumeNumberFloat) switch
} {
} <0 => -1,
else throw new FormatException($"Value could not be parsed"); >0 => 1,
_ => chapterNumberFloat.CompareTo(otherChapterNumberFloat)
};
} }
throw new ArgumentException($"{obj} can not be compared to {this}"); else throw new FormatException($"Value could not be parsed");
} }
/// <summary> /// <summary>