unoplatform / uno.extensions

Libraries to ease common developer tasks associated with building multi-platform mobile, desktop and web applications using Uno Platform or WinAppSDK.
https://platform.uno/
Other
71 stars 43 forks source link

[MVUX] Code generation fails for generic types #2366

Open kazo0 opened 1 week ago

kazo0 commented 1 week ago

If I try and create a generic class and use it as a Feed property on my model, the code generation for the model fails with:

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 'mvuxtestapp.Presentation.Iterator.g.cs' contains an invalid character '<' at position 33. (Parameter 'hintName')'. [/Users/steve/src/TestApps/mvuxtestapp/mvuxtestapp/mvuxtestapp.csproj] /Users/steve/src/TestApps/mvuxtestapp/mvuxtestapp/Presentation/MainModel.cs(21,81): warning CS8603: Possible null reference return. [/Users/steve/src/TestApps/mvuxtestapp/mvuxtestapp/mvuxtestapp.csproj]

My Model:

namespace mvuxtestapp.Presentation;

public partial record MainModel
{
    private INavigator _navigator;

    public MainModel(
        IStringLocalizer localizer,
        IOptions<AppConfig> appInfo,
        INavigator navigator)
    {
        _navigator = navigator;
        Title = "Main";
        Title += $" - {localizer["ApplicationName"]}";
        Title += $" - {appInfo?.Value?.Environment}";
    }

    public string? Title { get; }

    public IState<string> Name => State<string>.Value(this, () => string.Empty);
    public IState<Iterator<int>> Test => State<Iterator<int>>.Value(this, () => null);

    public async Task GoToSecond()
    {
        var name = await Name;
        await _navigator.NavigateViewModelAsync<SecondModel>(this, data: new Entity(name!));
    }

}

public record Iterator<T>(IImmutableList<T> Items)
{
    public int CurrentIndex { get; init; } = 0;
    public T CurrentItem => Items[CurrentIndex];
    public int Count => Items.Count;
    public bool CurrentIsLast => CurrentIndex == Items.Count - 1;
    public bool CanMoveNext => CurrentIndex < Items.Count - 1;
    public bool CanMovePrevious => CurrentIndex > 0;

    public Iterator<T> MoveNext()
        => CanMoveNext
            ? this with { CurrentIndex = CurrentIndex + 1 }
            : this;

    public Iterator<T> MovePrevious()
        => CanMovePrevious
            ? this with { CurrentIndex = CurrentIndex - 1 }
            : this;
}

mvuxtestapp.zip

kazo0 commented 1 week ago

fyi @dr1rrb / @Kunal22shah

This is causing us to use the hack as part of https://github.com/unoplatform/uno.chefs/pull/1181

Youssef1313 commented 1 week ago

We probably should re-use https://github.com/CommunityToolkit/Labs-Windows/blob/8d49097c09d5e07fa225d0fbf014cc4774c99cfb/components/AppServices/CommunityToolkit.AppServices.SourceGenerators/Extensions/ITypeSymbolExtensions.cs#L22 for the hint name