79651020

Date: 2025-06-03 09:56:02
Score: 0.5
Natty:
Report link

I wouldn't go with a constructor, but you could create a static method on the subclass (if you cannot alter the base class) that creates the ItemDetailViewModel from Models.AssetItem like this:

public static ItemDetailViewModel Create(Moddels.AssetItem model)
{
    var config = new MapperConfiguration(cfg => cfg.CreateMap<Models.AssetItem, ItemDetailViewModel>());

    var mapper = config.CreateMapper();

    return mapper.Map<ItemDetailViewModel>(model);
}

or you can create an extension method on the base class doing the same.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Goran