45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using Autolabor;
|
|
|
|
namespace LoraGamepad.Models;
|
|
|
|
public class CBPortItem
|
|
{
|
|
public string PortName { get; set; }
|
|
|
|
public CBPortItem(string name)
|
|
{
|
|
PortName = name;
|
|
}
|
|
public static ObservableCollection<CBPortItem> GetPortList()
|
|
{
|
|
ObservableCollection<CBPortItem> portList = new ObservableCollection<CBPortItem>();
|
|
List<SerialDevice> infos = SerialPort.FindPorts();
|
|
foreach (var portInfo in infos)
|
|
{
|
|
portList.Add(new CBPortItem(portInfo.port));
|
|
}
|
|
|
|
return portList;
|
|
}
|
|
}
|
|
|
|
public class CBPortItemCompare : IEqualityComparer<CBPortItem>
|
|
{
|
|
public bool Equals(CBPortItem? x, CBPortItem? y)
|
|
{
|
|
if (ReferenceEquals(x, y)) return true;
|
|
if (ReferenceEquals(x, null)) return false;
|
|
if (ReferenceEquals(y, null)) return false;
|
|
if (x.GetType() != y.GetType()) return false;
|
|
return x.PortName == y.PortName;
|
|
}
|
|
|
|
public int GetHashCode(CBPortItem obj)
|
|
{
|
|
return obj.PortName.GetHashCode();
|
|
}
|
|
} |