lucasteles / Strongly

💪🏾 A strongly-typed domain values source-generator
MIT License
35 stars 6 forks source link

Strongly generates a field that shadows constructor #9

Open AlexeyRaga opened 8 months ago

AlexeyRaga commented 8 months ago

This scenario is allowed and the compiler doesn't fail:

[Strongly]
public partial record struct ProductId(Guid Value);

However it generates an extra Value field that shadows the one that is provided in the constructor:

readonly partial record struct ProductId : System.IFormattable, System.IParsable<ProductId>
{
    public System.Guid Value { get; }

As a result, values that are created with the constructor are "missing" the provided inner value:

var pid = new ProductId(Guid.NewGuid());

// pid.value == Guid.Empty
AlexeyRaga commented 8 months ago

ref: https://github.com/graphql-dotnet/graphql-client/issues/622

lucasteles commented 7 months ago

Hi,

I believe it should be an error. The way we are dealing with records needs some improvement.

I would recommend until the fix use normal structs, if you are on a newer C# it is possible to define more succint than even records readonly partial struct ProductId;