SteveDunn / Vogen

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

CS0419 warning in `.g.cs` files when method overloading on auto generated functions #629

Closed Ledmonds closed 4 weeks ago

Ledmonds commented 4 weeks ago

Describe the feature

Hey Team,

We are running into a very small issue with the generated .g.cs files when method overloading on auto generated functions.

Given the below example where one would like to use an additional From() method, in addition to that which is automatically generated. The compiled result contains a CS0419 warning, as the cref now longer knows which From method is being referenced.

[ValueObject<string>(comparison: ComparisonGeneration.Omit)]
public readonly partial record struct ExampleId
{
    public static ExampleId NewId() => From(Guid.NewGuid().ToString());

    public static ExampleId From(Guid input) => From(input.ToString());

    private static Validation Validate(string input)
    {
        return !string.IsNullOrWhiteSpace(input)
            ? Validation.Ok
            : Validation.Invalid($"{nameof(ExampleId)} must not be null or whitespace");
    }
}

Let me know what you think, I'm happy to open a PR if this gains some traction.

SteveDunn commented 4 weeks ago

Hi @Ledmonds - thanks for the feedback. I've changed this to be specific to string. I also modified the comments for any Parse methods that might be hoisted from the users code. This will be in the next release. Thanks again!