2

I am creating a c# library that uses service references. I don't want the entire service to be accessible outside the library. So I first used AutoMapper to copy the service classes that I needed in to similar classes in my library. The second step was to make the service references internal. My main problem now is that there doesn't seem to be any auto mapping libraries that support internal access. I've tried AutoMapper, EmitMapper, and ValueInjecter libraries and all my copied objects have null/default values. AutoMapper has a github issue related to supporting internal, but there is no indication of when we will see it.

I've decided to try something oddball which was to Serialize the service class using JSON.NET and then to Deserialize it in to the library class. This works pretty well but I wonder how this compares to libraries like AutoMapper in terms of performance. I know that EmitMapper is king as far as performance.

Has anyone found an auto mapping solution that works for internals?

pixelshaded
  • 313
  • 1
  • 2
  • 10

1 Answers1

1

I've created a quick console program to test each library.

I create 10,000 objects which have 6 string properties that are set as GUIDs. Each test iterates through these objects, auto mapping them to a new object of a different type. I run the test 10 times for each auto mapping library and calculate the average timespan for each test in milliseconds.

  1. EmitMapper Average Time: 6.96822 milliseconds
  2. ValueInjector Average Time: 71.87465 milliseconds
  3. AutoMapper Average Time: 116.4615 milliseconds
  4. JsonMapper Average Time: 154.02429 milliseconds

The main purpose of this was to determine if using JSON.NET was a realistic alternative to the other main auto mapping libraries. Up front it seems to be competitive with AutoMapper so I think I have my answer.

pixelshaded
  • 313
  • 1
  • 2
  • 10