dotnet icon indicating copy to clipboard operation
dotnet copied to clipboard

Properties generated from private fields do not conflict/trigger CS0108 or any other warning

Open bzd3y opened this issue 8 months ago • 0 comments

Describe the bug

Given two types, where one is derived from the other, adding a private field to the derived type with the same name as a private field on the base type will generate a property on each type's generated partial definition. Because code analysis is disabled on these generated files, no indication is given that the property on the derived type is hiding the property on the base type.

Regression

No response

Steps to reproduce

The following code should demonstrate the problem:

public class TypeA : ObservableObject
{
    [ObservableProperty]
    private bool _someField; // will generate TypeA.SomeField
}

public class TypeB : TypeA
{
    [ObservableProperty]
    private bool _someField; // will generate TypeB.SomeField, hiding TypeA.SomeField
}

Expected behavior

Some indication should be given that TypeB._someField causes hiding of the property generated for TypeA, either CS0108 on the field or some MVVM specific warning that explains exactly what is happening.

Screenshots

No response

IDE and version

VS 2022

IDE version

17.13.6

Nuget packages

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

Nuget package version(s)

8.4.0

Additional context

No response

Help us help you

No, just wanted to report this

bzd3y avatar Jun 05 '25 12:06 bzd3y