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 文章,請原諒博主成為一個無恥的文檔搬運工!
  • 小弟剛邁入博客編寫,文中如有不對,歡迎用板磚扶正,希望給你有所幫助。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM