简体   繁体   English

具有自定义属性的 AutoMapper [AutoMapper]:如何在属性上添加条件

[英]AutoMapper with custom attribute[AutoMapper]: how to add a condition on a property

I'm using autoMapper and using attributes to map between entity and model. I want to add a condition when creating the map. I tried ForMember but it doesn't work since my condition is on a specific property and my sourceType and destinationType are somehow dynamic.我正在使用 autoMapper 并在实体和 model 之间使用 map 的属性。我想在创建 map 时添加一个条件。我尝试了 ForMember 但它不起作用,因为我的条件是针对特定属性的,而我的 sourceType 和 destinationType 不知何故动态的。 Is there a way to keep mapping with using attribute and at the same time add a condition on a property if it exists?有没有办法通过使用属性保持映射,同时在属性上添加条件(如果存在)?

That's not possible with attributes.这对属性来说是不可能的。 You'll have to switch to the fluent API.你必须切换到流利的 API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM