Skip to content

Commit

Permalink
Add OrderDirection.Reverse()
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriyDurov committed May 3, 2024
1 parent bf8838e commit 57bb8ea
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/BitzArt.LinqExtensions/Enums/OrderDirection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,25 @@ public enum OrderDirection : byte
/// </summary>
Descending = 1
}

/// <summary>
/// Extensions to <see cref="OrderDirection"/>.
/// </summary>
public static class OrderDirectionExtensions
{
/// <summary>
/// Reverse the order direction.
/// </summary>
/// <param name="orderDirection"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static OrderDirection Reverse(this OrderDirection orderDirection)
{
return orderDirection switch
{
OrderDirection.Ascending => OrderDirection.Descending,
OrderDirection.Descending => OrderDirection.Ascending,
_ => throw new ArgumentOutOfRangeException(nameof(orderDirection), orderDirection, null)
};
}
}

0 comments on commit 57bb8ea

Please sign in to comment.