mapperly icon indicating copy to clipboard operation
mapperly copied to clipboard

Generated code not compile

Open ngvtien opened this issue 1 year ago • 0 comments

Describe the bug The generated code is not compileable

Declaration code

// Relevant code of the Mapperly definition and all relevant classes
[Mapper]
public static partial class CardMapper
{
    public static partial Card MapToMembersCard(this CardDto dto);

    private static string?[] MapToStringArray(string?[] source)
    {
        var target = new string[source.Length];
        for (var i = 0; i < source.Length; i++)
        {
            target[i] = source[i] ?? throw new System.NullReferenceException($"Sequence {nameof(source)}, contained a null value at index {i}.");
        }
        return target;
    }
}

Actual relevant generated code

// Actual relevant code generated by Mapperly
// see also https://mapperly.riok.app/docs/configuration/generated-source/
[global::System.CodeDom.Compiler.GeneratedCode("Riok.Mapperly", "4.0.0.0")]
private static string?[] MapToStringArray(string?[] source)
{
}

Expected relevant generated code

// The generated code how you expect it to look like
private static string?[] MapToNulableStringArray(string?[] source)
{
    var target = new string[source.Length];
    for (var i = 0; i < source.Length; i++)
    {
        target[i] = source[i] ?? throw new System.NullReferenceException($"Sequence {nameof(source)}, contained a null value at index {i}.");
    }
    return target;
}

Environment (please complete the following information):

  • Mapperly Version: 4.0.0 but even 3.6.0
  • Nullable reference types: disable and enable
  • .NET Version: 8.0/6.0
  • Target Framework: net8.0 and net6.0
  • Compiler Version: [e.g. 4.8.0-3.23524.11 (f43cd10b), obtain with #error version in any .cs file]
  • C# Language Version: latest
  • IDE: Rider 2024.2.5
  • OS: Windows

Additional context Add any other context about the problem here.

ngvtien avatar Oct 22 '24 04:10 ngvtien