uno.extensions icon indicating copy to clipboard operation
uno.extensions copied to clipboard

[MVUX] Creating a `State<XXXModel>` break code gen if `XXXModel` is a `record`

Open dr1rrb opened this issue 1 year ago • 8 comments

Discussed in https://github.com/unoplatform/uno.extensions/discussions/2307

Result of investigation (with more details) can be found here : https://github.com/unoplatform/uno.extensions/discussions/2307#discussioncomment-9573080


Originally posted by mcNets May 25, 2024 Testing C# Markup + MVUX, while trying to reproduce the Counter example, I encountered an error when adding the second partial record, the BindableViewModel is not accessible anymore. I tried this in two different projects.

Build started at 10:55...
1>------ Build started: Project: UnoMvux1, Configuration: Debug Any CPU ------
1>Skipping analyzers to speed up the build. You can execute 'Build' or 'Rebuild' command to run analyzers.
1>CSC : warning CS8785: Generator 'FeedsGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'ArgumentException' with message 'The hintName 'UnoMvux1.MachineModel.g.cs' of the added source file must be unique within a generator.
1>c:\Test\UnoMvux1\UnoMvux1\MainPage.cs(9,30,9,47): error CS0246: The type or namespace name 'BindableMainModel' could not be found (are you missing a using directive or an assembly reference?)
1>Done building project "UnoMvux1.csproj" -- FAILED.

MainPage

public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this
            .Background(ThemeResource.Get<Brush>("ApplicationPageBackgroundThemeBrush"))
            .DataContext(new BindableMainModel(), (page, vm) => page
                .Content(new StackPanel()
                .VerticalAlignment(VerticalAlignment.Center)
                .HorizontalAlignment(HorizontalAlignment.Center)
                .Children(
                    new StackPanel()
                        .Orientation(Orientation.Vertical)
                        .Children(
                            new TextBlock()
                                .Text("Hello Uno Platform!")
                                .FontSize(24)
                                .Margin(10),

                            new Button()
                                .Content("Click me!")
                                .Margin(10)
                        )
                )));
    }
}

MainModel

internal partial record MainModel
{
    public IState<MachineModel> Machine => State.Value(this, () => new MachineModel("", ""));

    public ValueTask GetMachine() => Machine.UpdateAsync(m => m?.Load("100"));
}

MachineModel

internal partial record MachineModel(string Id, string Name)
{
    public MachineModel Load(string id)
    {
        return new MachineModel(id, $"Machine {id}");
    }
}

UnoMvux1.zip

dr1rrb avatar May 27 '24 18:05 dr1rrb