我想创建一个流畅的界面,可以像这样使用:
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 IListmappings; // 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;} }
我无法完成上述工作,但我确实创建了类似的工作方式,但我并不特别喜欢如何设置流畅的界面.我宁愿让它读起来像我上面的方式.