JasonBock / InlineMapping

Using the Compiler API for object mapping
MIT License
63 stars 11 forks source link

Add Mapping Via Serialization to the Performance Tests #36

Open JasonBock opened 1 year ago

JasonBock commented 1 year ago

Someone mentioned to me to add something like this to this list:

using Newtonsoft.Json;

public static class MappingThroughSerialization
{
    public static T Clone<T>(this object srcObject) where T : class
    {
        var destObject = JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(srcObject, JsonSettings.DefaultOptions_TypeNamePartial), JsonSettings.DefaultOptions_TypeNamePartial);
        return destObject;
    }
}

Basically, use serialization to map an object. I'm guessing that would be slower, but it would be interesting to add for comparison purposes.