Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with code generation #218

Closed
powerdude opened this issue Mar 3, 2024 · 2 comments · Fixed by #221
Closed

Error with code generation #218

powerdude opened this issue Mar 3, 2024 · 2 comments · Fixed by #221
Labels
bug Something isn't working investigation The issue is under investigation with the cooperation of the reporter

Comments

@powerdude
Copy link

Describe the bug
I'm trying to introduce these 2 classes:

public abstract  partial class BaseComponent2<TState> :Component<TState> where TState : class, new()
{
    [Inject] protected readonly IMediator Mediator;
    [Prop] protected MauiControls.Shell shellRef;
}

public abstract  partial class BaseComponent2<TState, TProps> :Component<TState,TProps> where TState : class, new()
    where TProps : class, new()
{
    [Inject] protected readonly IMediator Mediator;
    [Prop] protected MauiControls.Shell shellRef;   
}

To Reproduce
Create these 2 classes in your project:

public partial class ModelsPage : BaseComponent2<ModelsPage.PageState>
{

    public override VisualNode Render() =>
        new ContentPage
        {
            new CollectionView().AutomationId("list")
                .ItemsSource(State.Items, Render)
        };

    protected override void OnMounted()
    {
        Routing.RegisterRoute<ModelPage>("Model");

        //Mediator.Send(new GetModelsQuery())
        //    .Await(items => SetState(s => s.Items = items.ToArray()), ex => Trace.WriteLine(ex));

        base.OnMounted();
    }

    private VisualNode Render(Model item) =>
        new VStack(5)
            {
                new Label(item.Name).AutomationId(item.Id + "-name"),
                new Label(item.Id).AutomationId("id")
                    .FontSize(12)
                    .TextColor(Colors.Gray)
            }
            .OnTapped(
                async () => await shellRef.GoToAsync<ModelPage.Props2>(
                    "Model",
                    props => props.Id = item.Id))
            .Margin(5, 10);

    public class PageState
    {
        public Model[] Items { get; set; } =
        [
        ];
    }
}

public partial class ModelPage : BaseComponent2<ModelPage.PageState, ModelPage.Props2>
{
 
    public override VisualNode Render() =>
        new ContentPage("Muscle Group")
        {
            new Label(State.Item?.Name).AutomationId("name")
                .VCenter()
                .HCenter()
        };

    protected override void OnMountedOrPropsChanged()
    {
       // Do something
        base.OnMounted();
    }

    public class PageState
    {
        public Model Item { get; set; }
    }

    public class Props2
    {
        public string Id { get; set; } = null!;
    }
}

public record Model(string Id, string Name);

Expected behavior
Should work.

Additional context
Can work around it by giving the base classes different names.

@adospace
Copy link
Owner

adospace commented Mar 3, 2024

Sorry, what do you mean by "not working"? Do you see an exception? or it just doesn't compile?

@powerdude
Copy link
Author

The second class's partial class doesn't seem to get generated so, the mediator field does not get initialized. Possibly due to a duplicate generated filename problem since the filename just uses the class name and doesn't account for the type parameters

@adospace adospace added investigation The issue is under investigation with the cooperation of the reporter bug Something isn't working labels Mar 4, 2024
adospace added a commit that referenced this issue Mar 5, 2024
adospace added a commit that referenced this issue Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working investigation The issue is under investigation with the cooperation of the reporter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants