Fix CA1036

This commit is contained in:
RoosterDragon
2023-03-12 11:56:02 +00:00
committed by abcdefg30
parent ff799303b0
commit c442bd83f8
2 changed files with 16 additions and 8 deletions

View File

@@ -619,6 +619,9 @@ dotnet_diagnostic.CA1010.severity = warning
# Mark attributes with 'AttributeUsageAttribute'.
dotnet_diagnostic.CA1018.severity = warning
# Override methods on comparable types.
dotnet_diagnostic.CA1036.severity = warning
# Provide ObsoleteAttribute message.
dotnet_diagnostic.CA1041.severity = warning

View File

@@ -56,17 +56,27 @@ namespace OpenRA.Primitives
int Index(DelayedAction action)
{
// Returns the index of the next action with a strictly greater time.
var index = actions.BinarySearch(action);
var index = actions.BinarySearch(action, DelayedAction.TimeComparer);
if (index < 0)
return ~index;
while (index < actions.Count && action.CompareTo(actions[index]) >= 0)
while (index < actions.Count && DelayedAction.TimeComparer.Compare(action, actions[index]) >= 0)
index++;
return index;
}
}
readonly struct DelayedAction : IComparable<DelayedAction>
readonly struct DelayedAction
{
sealed class DelayedActionTimeComparer : IComparer<DelayedAction>
{
public int Compare(DelayedAction x, DelayedAction y)
{
return x.Time.CompareTo(y.Time);
}
}
public static IComparer<DelayedAction> TimeComparer = new DelayedActionTimeComparer();
public readonly long Time;
public readonly Action Action;
@@ -76,11 +86,6 @@ namespace OpenRA.Primitives
Time = time;
}
public int CompareTo(DelayedAction other)
{
return Time.CompareTo(other.Time);
}
public override string ToString()
{
return "Time: " + Time + " Action: " + Action;