如何使用泛型创建Fluent界面

 se8529106 发布于 2023-02-06 10:40

我想创建一个流畅的界面,可以像这样使用:

void Main() {
    ModelStateMappings.MapDomainModel().MapViewModel()
        .Properties(book => book.Author, vm => vm.AuthorsName)
        .Properties(book => book.Price, vm => vm.BookPrice);

    ModelStateMappings.MapDomainModel().MapViewModel()
        .Properties(store => store.Owner, vm => vm.OwnersName)
        .Properties(store => store.Location, vm => vm.Location);
}

我希望最终得到一个看起来像这样的集合:

static class ModelStateaMappings {
    private static IList mappings;
    // other methods in here to get it working
}

class ModelMappings {
    public Type DomainModelType {get;set;}
    public Type ViewModelType {get;set;}
    public IList PropertyMappings {get;set;}
}

class PropertyMapping {
    public Expression> DomainProperty {get;set;}
    public Expression> ViewModelProperty {get;set;}
}

我无法完成上述工作,但我确实创建了类似的工作方式,但我并不特别喜欢如何设置流畅的界面.我宁愿让它读起来像我上面的方式.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有