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.

Home Page:https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

Dabbel opened this issue · comments

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

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.2.2

Additional context

No response

Help us help you

Yes, but only if others can assist