Skip to content

Commit e182fb7

Browse files
committed
Optimize Nic selector list order
1 parent bcce297 commit e182fb7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

IPConfig/Models/SimpleNicType.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33

44
namespace IPConfig.Models;
55

6+
public class ConnectionTypeComparer : IComparer<ConnectionType>
7+
{
8+
public static readonly ConnectionTypeComparer Instance = new();
9+
10+
public int Compare(ConnectionType x, ConnectionType y)
11+
{
12+
int xOrder = GetConnectionTypeOrder(x);
13+
int yOrder = GetConnectionTypeOrder(y);
14+
15+
return xOrder.CompareTo(yOrder);
16+
}
17+
18+
private static int GetConnectionTypeOrder(ConnectionType connectionType)
19+
{
20+
return connectionType switch {
21+
ConnectionType.Ethernet => 0,
22+
ConnectionType.Wlan => 1,
23+
_ => throw new ArgumentOutOfRangeException(nameof(connectionType), connectionType, null)
24+
};
25+
}
26+
}
27+
628
public enum ConnectionType
729
{
830
Other,

IPConfig/ViewModels/NicViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ private async Task<List<Nic>> GetAllNicsAsync()
378378
? (int)x.OperationalStatus
379379
: Int32.MaxValue)
380380
.ThenBy(x => x.SimpleNicType, SimpleNicTypeComparer.Instance)
381+
.ThenBy(x => x.ConnectionType, ConnectionTypeComparer.Instance)
381382
.ThenBy(x => x.Name)
382383
.ToList());
383384

0 commit comments

Comments
 (0)