-
Type: Improvement
-
Resolution: Won't Do
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Feature Request, Serialization
-
None
Now the elements of enum `SortDirection` does not have int numbers:
```csharp
public enum SortDirection
{ Ascending, Descending }```
Because of this, a lot of logic in the code of `MongoDB.Driver` library to verify compliance with the elements and numbers (-1 and 1) like this:
```csharp
switch (_direction)
{ case SortDirection.Ascending: value = 1; break; case SortDirection.Descending: value = -1; break; default: throw new InvalidOperationException("Unknown value for " + typeof(SortDirection) + "."); }```
This is unnecessary logic, because the C# has built-in casting enum to Int32 via setting numbers for appropriate enum elements. So the enum `SortDirection` might be refactored like this:
```csharp
public enum SortDirection
{ Ascending = 1, Descending = -1 }```
In this case no more additional logic needed. And in the future, if this numbers will be changed (for example, `100` for `Ascending` and `200` for `Descending`), there is one place to change code - `SortDirection` enum.
Any string representation of `SortDirection` enum elements looks like this:
```csharp
$"ascending is: {(int) SortDirection.Ascending}"
```