The "Type conversion infrastructure service" for an interface-oriented extensible framework is what I think is the most important component beyond the core container
But in front of the blog, a lot of controversy, so I wrote a type of transformation of basic services and various mapper examples, by the way to make a simple comparison of the advantages and disadvantages of various mapper
My review of third-party components has three standards, one, usability, performance, third, ease of use
In this example four four kinds of mapper I have not used before (because I used to use their own mapper), the test may be inaccurate, the wrong place please correct me.
AutoMapper is using 4.2.1.0, need. net4.5 support (I didn't find it using NuGet. net4.0 available versions)
Emitmapper is using version 1.0, using the. net4.0
NLite is using 0.9.6, using. net4.0
Tinymapper is using 2.0.0.40, using. net4.0
One, simple package
1. Various Mappers package projects
2, various Mapper packaging class
3. Simple Personal First Impressions
3.1 AutoMapper DLL has 267k, larger, feel the function is very comprehensive
Support custom configuration, support static method and instance method, provide default instance, support Transfer type to transform, good extensibility, powerful function
3.2 Emitmapper DLL 99k, feel more concise function
Support custom configuration, provide default instance, support custom configuration
3.3 NLite DLL has 646k,dll, many of the features outside of Mapper, is a suite, if you need more than one of the functions is more cost-effective (not expand here)
3.4 Tinymapper DLL 47k, the lightest, if the function and performance are not compromised on the perfect
Ii. succession type conversion account test
1. Inheritance type conversion usability test code
We have to see clearly that no matter what kind of mapper, I use the same method (Globalservices.instance.convert<a, b> (A)) to invoke the
One, this is for the fairness of the various mapper tests, do not say that multiple if that multiple hashes
Second, that is, all kinds of mapper can use "plug-in" in the framework of the operation, if in order to suddenly find that some kind of mapper tool has "bug", Can "cut" for another mapper, all calls to the place almost do not have to modify
2. Test results
No problem, the above four kinds of mapper are easy to do, but there is a slight difference, automapper is directly using type conversion to deal with the conversion of inherited types, object references are the same. The other mapper should be "copy."
3. Performance test (100,000 times)
A:tinymapper fastest
B:automapper second (do not want to understand, direct type conversion should be counted "cheating", but not tinymapper fast)
C:emitmapper and Nlitemapper, Emitmappe slightly faster.
4, ease of use Needless to say, are very simple
Three, Simple object conversion account test
1. Test code
AutoMapper Incredibly transformation failure, really disappointing, online a search information, need to expand
2, the AutoMapper alone expansion re-test
The extension can be converted normally, and the extension is very simple, but why does this simple code have to be written by the user? I don't quite understand it at the moment, at least the ease of use is to deduct points
3. Performance test (100,000 times)
A:tinymapper to the jackpot (except Handcode), gratifying
B:emitmapper Second, the performance is good, emit sure good effect
C: Again is AutoMapper, is Emitmapper 1.5 times times about, AutoMapper not as bad as I imagined
D:nlitemapper bottom, not quite understand, as if online have said Nlitemapper also use emit do, perhaps I use this version is not emit (for as long as possible, I try to use. net4.0)
4, usability Summary, AutoMapper deduction, simple mapping or manual registration of rules
People online every time you use AutoMapper to try to register, although the ugly point is a way, do not know whether to affect the performance attempt
IV. Member Name Mapping account testing
1. Test code
Configuration rules for AutoMapper
Configuration rules for Emitmapper
Configuration rules for Tinymapper
In fact, the demand is very simple, convert a to C, but to map the id attribute of a to the aid property of C, but nlitemapper I did not find the configuration method
2. Test results
Nlitemapper I did not find the configuration method, so the aid property did not convert successfully, preliminary judgment Nlitemapper cannot support this demand
3. Performance test (100,000 times)
A:tinymapper continues to be the top, and far ahead
B:emitmapper second, far worse than Tinymapper, support for this configuration rule is not good
C: Again is automapper, is worse than Tinymapper, or to this configuration rule support is not good
D:nlitemapper performance is at the bottom and not yet fulfilled
4. Ease of Use
A:tinymapper is the most "graceful" way to expand, using expressions to add new mapping rules with the highest score
B:automapper the way to extend second, because each pair of types are configured to be flawed
C:emitmapper extension of the way a bit bad, is hard coding, but the performance is much worse than hard coding, than the tinymapper are a lot worse (reason can be explored later)
D:nlitemapper bottom, no need to fulfill
Five, tree-like recursive conversion course test
1. Test code
The above code is deliberately put Tinymapper annotated, is to test alone (Tinymapper will be a serious error)
2. Test results
2.1. Test Tinymapper alone
A: This time tinymapper, it is estimated that I test the example of special, sub-object type is itself triggered by a bug, serious bugs, not only can not be converted successfully, the direct death cycle
Note: I do not know whether the latest version of Tinymapper has this problem, interested can test
B: The other three kinds of mapper are capable
3, Performance test (100,000 times, except Tinymapper)
A: This time emitmapper the jackpot.
B:automapper and Nlitemapper almost, automapper slightly better
C:tinymapper absent, execution will be error
4. Ease of Use
AutoMapper mishap, each pair of types to be configured
ASP. Use "Type conversion base service" to test four types of mapper (AutoMapper, Emitmapper, Nlitemapper, and Tinymapper) for an interface extensible framework