EmitMapper系列之一:EmitMapper入門 EmitMapper的總結

EmitMapper的總結

EmitMapper簡介

前言:

  參考官網: http://emitmapper.codeplex.com/html

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 文章,請原諒博主成爲一個無恥的文檔搬運工!
  • 小弟剛邁入博客編寫,文中若有不對,歡迎用板磚扶正,但願給你有所幫助。
相關文章
相關標籤/搜索