EmitMapper系列之一:EmitMapper入门

EmitMapper的总结

EmitMapper简介

前言:

  参考官网: http://emitmapper.codeplex.com/

Project Description
Powerful customisable tool
for mapping entities to each other. Entities can be plain objects, DataReaders, SQL commands and anything you need. The tool uses run-time code
generation via the Emit library. It is usefull for dealing with DTO objects, data access layers an so on.

官方原文翻译:
项目描述
用于将实体映射到彼此的强大的可定制工具。实体可以是纯对象,DataReaders,SQL命令以及任何您需要的。该工具通过Emit库生成运行时代码。处理DTO对象,数据访问层等都是有用的。

优点:

我们看看官方怎么说???我想官方给了四点足以让你在相应的项目中使用它

  1. Extremely fast. It effectively uses the Emit library to generate mappers at run-time direct in IL as though these mappers are written by hand. Most other mappers use the Reflection library for mapping (or source code generation). Also EmitMapper minimizes boxing-unboxing operations and additional calls during mapping. For example it performs type conversion for value-types without boxing-unboxing and converts nested members without recursion (one-pass algorithm) when it is possible.
  2. Easy to use. Emit Mapper produces mappers at run time and there is no need for special complex build process unlike some other libraries which perform source code generation. Emit Mapper API is as simple as possible. You don't need to create any tedious XML document, or scatter strange attributes on your objects. Mapper can be created by one method call. But if you need fine-grained mapping configuration, you can easily reach it.
  3. Flexible. Emit Mapper doesn't have any hardcoded mapping strategy (special mapping attributes, XML documents or whatever) unlike most other mapping libraries. Instead, Emit Mapper has extremely flexible API and you can define any mapping yourself. For example you can define automatic mapping for DataReader to your business-objects. In general, Emit Mapper can be used as high performance tool for dynamic access to object properties and fields.
  4. Multi-Platform. The Emit Mapper can be run on Microsoft .NET Framework, Silverlight and Mono

    官方给出四个优点

  1. 非常快 它有效地使用Emit库在IL中直接在运行时生成映射器,就好像这些映射器是用手写的。大多数其他映射器使用Reflection库进行映射(或源代码生成)。此外,EmitMapper还可以最大限度地减少打击拆箱操作和映射期间的其他调用。例如,对于没有打包装箱的值类型,它执行类型转换,并在可能时转换嵌套成员而不进行递归(一次通过算法)。
  2. 使用方便。Emit Mapper在运行时生成映射器,与执行源代码生成的其他库不同,不需要特殊的复杂构建过程。Emit Mapper API尽可能简单。您不需要创建任何繁琐的XML文档,或在对象上散布奇怪的属性。Mapper可以通过一种方法调用创建。但是,如果您需要细粒度的映射配置,您可以轻松实现。
  3. 灵活。与大多数其他映射库不同,Emit Mapper没有任何硬编码映射策略(特殊映射属性,XML文档或其他任何内容)。相反,Emit Mapper具有非常灵活的API,您可以自己定义任何映射。例如,您可以为DataReader定义自动映射到业务对象。通常,Emit Mapper可以用作动态访问对象属性和字段的高性能工具。
  4. 多平台。Emit Mapper可以在Microsoft .NET Framework,Silverlight和Mono上运行。

类型转换:

Emit Mapper can automatic convert the following types:
  1. Anything to string using the ToString() method.
  2. Primitive types using System.Convert class.
  3. Nullable types to value types and vice-versa.
  4. Enum to its underlying type and vice-versa.
  5. Enum to string and vice-versa.
  6. Collections of different types to each other (arrays, ArrayList, List<>, IEnumerable)
  7. classes to structures and vice-versa.
  8. Complex types with complex nested members using recursive mapping with shallow or deep copieng.
Emit Mapper可以自动转换以下类型:
  1. 任何使用ToString()方法进行字符串处理。
  2. 使用System.Convert类的基本类型。
  3. Nullable类型对值类型,反之亦然。
  4. 枚举为其底层类型,反之亦然。
  5. 枚举到字符串,反之亦然。
  6. 不同类型的集合(数组,ArrayList,List <>,IEnumerable)
  7. 类到结构,反之亦然。
  8. 具有复杂嵌套成员的复杂类型使用具有浅或深对应的递归映射。
 
 

 总结:官方的描述,也可以在面试过程中进行简述,加分项。。。。。

  • 博主是利用读书、参考、引用、抄袭、复制和粘贴等多种方式打造成自己的纯镀 24k 文章,请原谅博主成为一个无耻的文档搬运工!
  • 小弟刚迈入博客编写,文中如有不对,欢迎用板砖扶正,希望给你有所帮助。

转载于:https://www.cnblogs.com/lrzr/p/7515703.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值