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

[ObservableProperty] Does it support Interface Property Implementation #649

Closed cgp1976 closed 1 year ago

cgp1976 commented 1 year ago

Describe the bug

public interface MyInterface 
{
    public List<object> Items { get; set;}
}

public partial class MyViewModel: MyInterface 
{
     [ObservableProperty] // ---<  over here visual studio throw error CS0535
     private List<object> _item=null;
}

Steps to reproduce

try the code with visual studio it will generate compile error with code CS0535

IDE and version

VS 2022 Preview

IDE version

Microsoft Visual Studio Professional 2022 (ARM 64-bit) - Preview Version 17.6.0 Preview 2.0

Nuget packages

Nuget package version(s)

CommunityToolkit.Mvvm 8.1.0

Help us help you

No, just wanted to report this

Sergio0694 commented 1 year ago

This is the expected behavior, your code just has a bug. The interface member is called "Items", but the field in the class is called "_item" (without the final "s"), so the generated property will be "Item" and not "Items" 😄