添加项目文件。
This commit is contained in:
30
CapMachine.Wpf/MapperProfile/ChartSelectProfile.cs
Normal file
30
CapMachine.Wpf/MapperProfile/ChartSelectProfile.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
CapMachine.Wpf/MapperProfile/ChartYAxisProfile.cs
Normal file
19
CapMachine.Wpf/MapperProfile/ChartYAxisProfile.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
14
CapMachine.Wpf/MapperProfile/IMapperProvider.cs
Normal file
14
CapMachine.Wpf/MapperProfile/IMapperProvider.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
34
CapMachine.Wpf/MapperProfile/MapperConfig.cs
Normal file
34
CapMachine.Wpf/MapperProfile/MapperConfig.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user