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
1.9k views
in Technique[技术] by (71.8m points)

c# - An expression tree may not contain an out argument variable declaration AutoMapper map from

I have the following mapping (AutoMapper Version="10.1.1"):

CreateMap<FooClass, BarClass>()
    .ForMember(
        dest => dest.Status, 
        opt => opt.MapFrom(
            src => Enum.TryParse(src.Status ?? string.Empty, out Status result) ? result : Status.TEST_READY)
    );

But got an error:

CS8198: An expression tree may not contain an out argument variable declaration

Any idea how to accomplish this without needing to create a custom resolver?

Thanks

question from:https://stackoverflow.com/questions/65838330/an-expression-tree-may-not-contain-an-out-argument-variable-declaration-automapp

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

1 Answer

0 votes
by (71.8m points)

Try add src and destination (dest) in lambda.

CreateMap<FooClass, BarClass>()
    .ForMember(
        dest => dest.Status, 
        opt => opt.MapFrom(
            (src, dest) => Enum.TryParse(src.Status ?? string.Empty, out Status result) ? result : Status.TEST_READY)
    );

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

...