automapper框架优化
This commit is contained in:
@@ -10,7 +10,7 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// 串口连接配置对话框 VM。
|
||||
/// 通过 DialogParameters 接收宿主 DeviceInfoModel;保存时把副本写回宿主。
|
||||
/// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。
|
||||
/// </summary>
|
||||
public class SerialPortConfigViewModel : DialogViewModelBase
|
||||
{
|
||||
@@ -23,8 +23,8 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
set => SetProperty(ref _title, value);
|
||||
}
|
||||
|
||||
private SerialPortConnectionConfig _config = new();
|
||||
public SerialPortConnectionConfig Config
|
||||
private SerialPortConfigVM _config = new();
|
||||
public SerialPortConfigVM Config
|
||||
{
|
||||
get => _config;
|
||||
set => SetProperty(ref _config, value);
|
||||
@@ -70,7 +70,7 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
public ICommand RefreshPortsCommand { get; }
|
||||
#endregion
|
||||
|
||||
private DeviceInfoModel? _hostDevice;
|
||||
private DeviceInfoVM? _hostDevice;
|
||||
|
||||
public SerialPortConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
@@ -126,7 +126,7 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
|
||||
if (_hostDevice != null)
|
||||
{
|
||||
_hostDevice.SerialPortConfig ??= new SerialPortConnectionConfig();
|
||||
_hostDevice.SerialPortConfig ??= new SerialPortConfigVM();
|
||||
Config.CopyTo(_hostDevice.SerialPortConfig);
|
||||
_hostDevice.ConnectionType = "Serial";
|
||||
}
|
||||
@@ -143,13 +143,13 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
|
||||
if (parameters.ContainsKey("Device"))
|
||||
{
|
||||
_hostDevice = parameters.GetValue<DeviceInfoModel>("Device");
|
||||
_hostDevice = parameters.GetValue<DeviceInfoVM>("Device");
|
||||
Title = $"串口连接配置 - {_hostDevice?.DeviceName}";
|
||||
Config = new SerialPortConnectionConfig(_hostDevice?.SerialPortConfig);
|
||||
Config = new SerialPortConfigVM(_hostDevice?.SerialPortConfig);
|
||||
}
|
||||
else if (parameters.ContainsKey("Config"))
|
||||
{
|
||||
Config = new SerialPortConnectionConfig(parameters.GetValue<SerialPortConnectionConfig>("Config"));
|
||||
Config = new SerialPortConfigVM(parameters.GetValue<SerialPortConfigVM>("Config"));
|
||||
}
|
||||
|
||||
RefreshPorts();
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
{
|
||||
/// <summary>
|
||||
/// TCP 连接配置对话框 VM。
|
||||
/// 通过 DialogParameters 接收宿主 DeviceInfoModel;保存时把副本写回宿主。
|
||||
/// 通过 DialogParameters 接收宿主 DeviceInfoVM;保存时把副本写回宿主。
|
||||
/// </summary>
|
||||
public class TCPConfigViewModel : DialogViewModelBase
|
||||
{
|
||||
@@ -23,8 +23,8 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
}
|
||||
|
||||
/// <summary>编辑用的副本,取消时不会污染宿主对象。</summary>
|
||||
private TcpConnectionConfig _config = new();
|
||||
public TcpConnectionConfig Config
|
||||
private TcpConfigVM _config = new();
|
||||
public TcpConfigVM Config
|
||||
{
|
||||
get => _config;
|
||||
set => SetProperty(ref _config, value);
|
||||
@@ -57,7 +57,7 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
#endregion
|
||||
|
||||
// 用于保存时把副本回写到原对象
|
||||
private DeviceInfoModel? _hostDevice;
|
||||
private DeviceInfoVM? _hostDevice;
|
||||
|
||||
public TCPConfigViewModel(IContainerProvider containerProvider) : base(containerProvider)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
// 把副本写回宿主
|
||||
if (_hostDevice != null)
|
||||
{
|
||||
_hostDevice.TcpConfig ??= new TcpConnectionConfig();
|
||||
_hostDevice.TcpConfig ??= new TcpConfigVM();
|
||||
Config.CopyTo(_hostDevice.TcpConfig);
|
||||
_hostDevice.ConnectionType = "TCP";
|
||||
}
|
||||
@@ -120,13 +120,13 @@ namespace SettingModule.ViewModels.Dialogs
|
||||
|
||||
if (parameters.ContainsKey("Device"))
|
||||
{
|
||||
_hostDevice = parameters.GetValue<DeviceInfoModel>("Device");
|
||||
_hostDevice = parameters.GetValue<DeviceInfoVM>("Device");
|
||||
Title = $"TCP 连接配置 - {_hostDevice?.DeviceName}";
|
||||
Config = new TcpConnectionConfig(_hostDevice?.TcpConfig);
|
||||
Config = new TcpConfigVM(_hostDevice?.TcpConfig);
|
||||
}
|
||||
else if (parameters.ContainsKey("Config"))
|
||||
{
|
||||
Config = new TcpConnectionConfig(parameters.GetValue<TcpConnectionConfig>("Config"));
|
||||
Config = new TcpConfigVM(parameters.GetValue<TcpConfigVM>("Config"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace SettingModule.ViewModels
|
||||
set => SetProperty(ref _testStatus, value);
|
||||
}
|
||||
|
||||
public DeviceInfoModel? SelectedDevice
|
||||
public DeviceInfoVM? SelectedDevice
|
||||
{
|
||||
get => _selectedDevice;
|
||||
set
|
||||
@@ -40,7 +40,7 @@ namespace SettingModule.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public ObservableCollection<DeviceInfoModel> DeviceList
|
||||
public ObservableCollection<DeviceInfoVM> DeviceList
|
||||
{
|
||||
get => _deviceList;
|
||||
set => SetProperty(ref _deviceList, value);
|
||||
@@ -70,8 +70,8 @@ namespace SettingModule.ViewModels
|
||||
private GlobalInfo _globalInfo { get; }
|
||||
private bool IsInitiated = false;
|
||||
private string _testStatus = string.Empty;
|
||||
private DeviceInfoModel? _selectedDevice;
|
||||
private ObservableCollection<DeviceInfoModel> _deviceList;
|
||||
private DeviceInfoVM? _selectedDevice;
|
||||
private ObservableCollection<DeviceInfoVM> _deviceList;
|
||||
private string _statusMessage = "请在左侧选择设备查看 / 编辑配置";
|
||||
#endregion
|
||||
public SettingViewModel(IContainerExtension container) : base(container)
|
||||
|
||||
Reference in New Issue
Block a user