Vogen icon indicating copy to clipboard operation
Vogen copied to clipboard

Generate a marker interface IVogenValue<T>

Open marcwittke opened this issue 6 months ago • 1 comments

Describe the feature

It would be really useful, if the generated type would implement a marker interface like IVogenValue<T>.

This would enable us to check for such interface when adding a generic mapping function to a mapper library like AutoMapper, Mapperly or Mapster.

I am currently using Mapperly, and my static mapper class looks like this

    private static int ToInt(Count count) => count.Value;

    private static int ToInt(CircuitId id) => id.Value;

    private static int ToInt(PublisherId id) => id.Value;

    private static int ToInt(PublisherProfileId id) => id.Value;

    private static string ToString(IPhoneNumber phoneNumber) => phoneNumber.Value;

    private static string ToString(EmailAddress emailAddress) => emailAddress.Value;

this screams DRY! and could be replaced by

private static T ToPrimitive<T>(IVogenValue<T> valueObject) => valueObject.Value;

Edit: well, it's still not working in Mapperly, because of https://github.com/riok/mapperly/issues/1285 but it would work in AutoMapper...

marcwittke avatar Jun 16 '25 19:06 marcwittke

Could you please check if IVogen<TSelf, TPrimitive> solves the issue? For more details, please refer to the documentation.

shupoval avatar Jun 19 '25 14:06 shupoval

@marcwittke did @shupoval 's suggest solve your issue?

SteveDunn avatar Jul 18 '25 04:07 SteveDunn

I did not dig further into it because I prefer to use mapperly over others, and just with this library my idea wouldn't work either. But it looks like exactly what I was looking for, yes.

marcwittke avatar Jul 18 '25 16:07 marcwittke