CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
3.07k stars 299 forks source link

`RelayCommandAttribute` can't be used with interface and generic class #817

Open Dabbel opened 10 months ago

Dabbel commented 10 months ago

Describe the bug

If you have an interface, without a generic type, that requires the implementation of an ICommand property it isn't possible to use the RelayCommandAttribute on a generic class that uses the generic type as parameter on the command method. The RelayCommandAttribute generates a property of type IRelayCommand<T> that doesn't satisfy the implementation of the interface.

Regression

No response

Steps to reproduce

public interface ITest
{
    ICommand TestSomethingCommand { get; }
}

public partial class Test<T> : ITest
{
    // Generates a property of type IRelayCommand<T>, this doesn't satisfy ITest.ICommand
    [RelayCommand]
    private void TestSomething(T obj)
    {
    }
}

Expected behavior

The generated property should be of type ICommand or RelayCommandAttribute should have an option to generate the property with of type ICommand instead of IRelayCommand<T>.

Screenshots

No response

IDE and version

VS 2022, Rider

IDE version

No response

Nuget packages

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

Yes, but only if others can assist