AutoMapper VS ValueInjecter [英] AutoMapper vs ValueInjecter

查看:750
本文介绍了AutoMapper VS ValueInjecter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我正在寻找在计算器上 AutoMapper 的东西,我读一些有关的 ValueInjecter

Everytime I'm looking for AutoMapper stuff on StackOverflow, I'm reading something about ValueInjecter.

有人能告诉我利弊他们(性能,功能,API的使用,可扩展性测试)的?

Can somebody tell me the pros and cons between them (performance, features, API usage, extensibility, testing) ?

推荐答案

作为 ValueInjecter ,我可以告诉大家的创造者你说我这样做是因为我想要的东西的简单,非常灵活

as the creator of ValueInjecter, I can tell you that I did it because I wanted something simple and very flexible

我真的不喜欢写太多或写入大量猴子$ C $的C 这样的:

I really don't like writing much or writing lots of monkey code like:

Prop1.Ignore, Prop2.Ignore etc.
CreateMap<Foo,Bar>(); CreateMap<Tomato, Potato>(); etc.

ValueInjecter东西如Mozilla与它的插件,创建ValueInjections并使用它们。

ValueInjecter is something like mozilla with it's plugins, you create ValueInjections and use them

有内置的平坦化,unflattening,有的注射那些旨在被继承

there are built-in injections for flattening, unflattening, and some that are intended to be inherited

和它的作品多在一个方面类型的方式后,您不必指定所有属性1比1,而不是你做的是这样的:

and it works more in an aspect type of way, you don't have to specify all properties 1-to-1, instead you do something like:

把所有的INT属性从名称以ID结束源,转换价值,并设置每个在同名源对象的属性没有标识后缀,它的类型是从实体的东西继承像

这样一个明显的区别,ValueInjecter甚至在与扁平化和unflattening窗口的形式使用,这是它是如何灵活

(从对象映射到表单控件和背面)

(mapping from object to form controls and back)

Automapper,在Windows窗体,没有unflatenning不能使用,但它有一个像集合映射好东西,所以如果你需要它ValueInjecter你只是这样做:

Automapper, not usable in windows forms, no unflatenning, but it has good stuff like collections mapping, so in case you need it with ValueInjecter you just do something like:

foos.Select(O =方式&gt;新的酒吧()InjectFrom(O));

您也可以使用ValueInjecter从地图匿名动态对象

you can also use ValueInjecter to map from anonymous and dynamic objects

的区别:


  • automapper创建为每个映射可能性CreateMap)配置(

  • automapper create configuration for each mapping possibility CreateMap()

valueinjecter从任何对象注入到任何对象(也有情况下,当你从对象到值类型注入)

valueinjecter inject from any object to any object (there are also cases when you inject from object to valuetype)

automapper已建成平坦化它,只为简单类型或同一类型,并且它不具有unflattening

automapper has flattening built it, and only for simple types or from same type, and it doesn't has unflattening

valueinjecter只有当你需要它,你做的 target.InjectFrom&LT; FlatLoopValueInjection&GT;(源);也&LT; UnflatLoopValueInjection&GT;
如果您从 String类型的Foo.Bar.Name想型的Class1 的FooBarName你继承FlatLoopValueInjection并指定此

valueinjecter only if you need it you do target.InjectFrom<FlatLoopValueInjection>(source); also <UnflatLoopValueInjection> and if you want from Foo.Bar.Name of type String to FooBarName of type Class1 you inherit FlatLoopValueInjection and specify this

automapper默认情况下并为您必须指定一个接一个,做的东西一样Prop1.Ignore(),Prop2.Ignore()等。

automapper maps properties with same name by default and for the rest you have to specify one by one, and do stuff like Prop1.Ignore(), Prop2.Ignore() etc.

valueinjecter具有确实具有相同名称和类型的属性默认注射.InjectFrom();对于一切你创建一个单独的映射逻辑/规则,更像方面,例如自定义valueinjections从Foo类型为类型栏的所有道具全部道具的

valueinjecter has a default injection .InjectFrom() that does the properties with the same name and type; for everything else you create your custom valueinjections with individual mapping logic/rules, more like aspects, e.g. from all props of Type Foo to all props of type Bar

这篇关于AutoMapper VS ValueInjecter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆