SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
887 stars 46 forks source link

`fromPrimitiveCasting` and `toPrimitiveCasting` aren't consistent across `[ValueObject]` and `[VogenDefaults]` #610

Closed aradalvand closed 5 months ago

aradalvand commented 5 months ago

Describe the bug

This:

[ValueObject<Guid>(toPrimitiveCasting: CastOperator.Implicit)]

Generates this:

public static implicit operator System.Guid(GatewayId vo)

Whereas this:

[assembly: VogenDefaults(toPrimitiveCasting: CastOperator.Implicit)]

Generates this:

public static implicit operator GatewayId(System.Guid value)

It makes no sense. This is a bug. public static implicit operator GatewayId(System.Guid value) represents a cast "to" the primitive, so what [ValueObject] does is the correct behavior here.

Steps to reproduce

Outlined above.

Expected behaviour

[assembly: VogenDefaults(toPrimitiveCasting: CastOperator.Implicit)]

should do what

[ValueObject<Guid>(toPrimitiveCasting: CastOperator.Implicit)]

does.

SteveDunn commented 5 months ago

Thanks for the bug report @aradalvand - well spotted. This has been fixed and will be available in the next release in a few hours.

aradalvand commented 5 months ago

@SteveDunn Thanks a lot for the quick fix! (Hopefully 1K stars soon!)