Skip to content

Commit 727d19c

Browse files
authored
Update README.md
1 parent 238a68f commit 727d19c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,42 @@ public class OrderSubmittedEventConsumer : IConsumer<OrderSubmitted>
200200
}
201201
}
202202
```
203+
## AA.AutoMapper用法
204+
##### 实现IMapperConfiguration接口,创建映射规则配置
203205

206+
```
207+
public class WebMapperConfigurations : IMapperConfiguration
208+
{
209+
public int Order { get { return 0; } }
210+
211+
public Action<IMapperConfigurationExpression> GetConfiguration()
212+
{
213+
Action<IMapperConfigurationExpression> action = cfg =>
214+
{
215+
cfg.CreateMap<UserVm, UserInput>();
216+
};
217+
return action;
218+
}
219+
}
220+
```
221+
##### 在程序startup调用配置
222+
223+
```
224+
var mapperConfig = new WebMapperConfigurations();
225+
AutoMapperConfiguration.Init(new List<Action<IMapperConfigurationExpression>> { mapperConfig.GetConfiguration() });
226+
ObjectMapping.ObjectMapManager.ObjectMapper = new AutoMapperObjectMapper();
227+
```
228+
##### 利用扩展方法MapTo执行映射
229+
230+
```
231+
[Fact]
232+
public void TestMap()
233+
{
234+
//init
235+
Init();
236+
UserVm userVm = new UserVm { Id = 1, Name = "成天" ,Remark="微信公众号:dotNet知音"};
237+
var userDto = userVm.MapTo<UserInput>();
238+
//var userDto2 = userVm.MapTo<UserVm,UserInput>();
239+
240+
}
241+
```

0 commit comments

Comments
 (0)