我可以使用带有lambda表达式的三元运算符吗?

时间:2016-07-18 18:41:51

标签: c# lambda automapper

我试图理解我是否可以在lambda表达式中使用三元运算符。

例如:

public class Foo
{
    public int ID {get; set;}
    public string Name {get; set;}
    public Address MyAdd {get; set;}
}

然后我想做这样的事情:

        var config = new MapperConfiguration(c =>
        {
            c.CreateMap<foo, MyFoo>()
            .ForMember(x => x.ID, m => m.MapFrom(a => a.ID))
            .ForMember(x => x.Name, m => m.MapFrom(a => a.Name))
            .ForMember(x => x.Add1, m => m.MapFrom(a => (a.MyAdd != null) ? a.MyAdd.Line1 : string.Empty));
        });

然而我收到错误:

Cannot convert lambda expression to type 'string' because it is not a delegate type

0 个答案:

没有答案