添加项目文件。

This commit is contained in:
2024-07-04 17:42:03 +08:00
parent dc72862945
commit 1bd6cd358f
71 changed files with 7218 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
using AutoMapper;
using CapMachine.Model;
using CapMachine.Wpf.Models;
namespace CapMachine.Wpf.MapperProfile
{
/// <summary>
/// 源类的属性名称和目标类的属性名称相同不区分大小写直接匹配Mapper.CreateMap<source,dest>();无需做其他处理,此处不再细述
/// 1智能匹配
///  AutoMapper能够自动识别和匹配大部分对象属性:
/// 如果源类和目标类的属性名称相同,直接匹配,不区分大小写
/// 目标类型的CustomerName可以匹配源类型的Customer.Name
/// 目标类型的Total可以匹配源类型的GetTotal() 方法
/// </summary>
public class ChartSelectProfile : Profile
{
public ChartSelectProfile()
{
CreateMap<ConfigChartSelect, ChartSelectDto>()
.ForMember(dest => dest.Index, opt => opt.MapFrom(src => src.Index))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
//.ForMember(dest => dest.Id, opt => opt.Ignore())//忽略目标类中的属性
//.ForMember(dest => dest.OrderDate, opt => opt.UserValue<DateTime>(DateTime.Now)); //固定值匹配
//.ForMember(dest => dest.TotalAmount, opt => opt.MapFrom(src => src.TotalAmount ?? 0)) //复杂的匹配
//.ForMember(dest => dest.EventDate, opt => opt.MapFrom(src => src.WorkEvent.Date)) //属性匹配匹配源类中WorkEvent.Date到EventDate
.ForMember(dest => dest.YAxis, opt => opt.MapFrom(src => src.ConfigChartYAxis))//
.ReverseMap();
}
}
}

View File

@@ -0,0 +1,19 @@
using AutoMapper;
using CapMachine.Model;
using CapMachine.Wpf.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.MapperProfile
{
public class ChartYAxisProfile:Profile
{
public ChartYAxisProfile()
{
CreateMap<ChartYAxisDto,ConfigChartYAxis>().ReverseMap();
}
}
}

View File

@@ -0,0 +1,14 @@
using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.MapperProfile
{
public interface IMapperProvider
{
IMapper GetMapper();
}
}

View File

@@ -0,0 +1,34 @@
using AutoMapper;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.MapperProfile
{
public class MapperConfig : IMapperProvider
{
private readonly MapperConfiguration _Configuration;
public MapperConfig(IContainerProvider container)
{
_Configuration = new MapperConfiguration(configure =>
{
//var assemblys = AppDomain.CurrentDomain.GetAssemblies();
//configure.AddMaps(assemblys);
configure.ConstructServicesUsing(container.Resolve);
//扫描profile文件
configure.AddMaps(AppDomain.CurrentDomain.GetAssemblies());
});
}
public IMapper GetMapper()
{
return _Configuration.CreateMapper();
}
}
}