Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
739 views
in Technique[技术] by (71.8m points)

c# - Automapper: Map property name from source to destination

I have a source class like this:

public class SuspenseRequest
{
    public string LineOfBusiness { get; set; }

    public string SuspendedTo { get; set; }

    public string DbAction { get; set; }

    public string OfficeName { get; set; }

    public string Priority { get; set; }

    public string State { get; set; }
}

My destination class is:

public class SearchCriteria
{
    public Guid Id { get; set; }

    public string ParameterName { get; set; }

    public string ParameterValue { get; set; }

    public bool isProcessed { get; set; }
}

What I am trying to do is to map the property names of SuspenseRequest to ParameterName from the SearchCriteria class. So LineOfBusiness property or SuspendedTo property or DbAction property is mapped to ParameterName

So I tried to define the following mapping and I am stuck at this point where when I use to getProperty method, it is asking me to pass in the string:

    CreateMap<SuspenseRequest, SearchCriteria>()
        .ForMember(dest => dest.ParameterName, opt => opt.MapFrom(src => src.GetType().GetProperty(opt.));

How do I perform this mapping with Automapper? Thanks in advance


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...