automapper框架优化

This commit is contained in:
hsc
2026-06-10 15:04:11 +08:00
parent 5452857299
commit 2e07c0c446
43 changed files with 612 additions and 293 deletions

View File

@@ -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"));
}
}