How to configure Conditional Mapping in AutoMapper?

后端 未结 4 1401
花落未央
花落未央 2020-12-13 17:48

Suppose I have the following entities (classes)

public class Target
{
    public string Value;
}


public class Source
{
    public string Value1;
    public         


        
4条回答
  •  自闭症患者
    2020-12-13 18:08

    AutoMapper allows you to add conditions to properties that must be met before that property will be mapped.

    I was doing the mapping with some enum conditions, have a look that is little effort for the community from my side.

    }

    .ForMember(dest => dest.CurrentOrientationName, 
                 opts => opts.MapFrom(src => src.IsLandscape? 
                                            PageSetupEditorOrientationViewModel.Orientation.Landscape : 
                                            PageSetupEditorOrientationViewModel.Orientation.Portrait));
    

提交回复
热议问题