Incorrect partial method prototypes for generated observable properties

Đang mở
#1,109 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
tooling

Hướng nghiên cứu

Bắt đầu với việc tái hiện trên .NET 9 bằng CommunityToolkit.Mvvm 8.4.0, so sánh các khai báo partial methods được tạo cho field và property [ObservableProperty]. Xác minh các prototype của OnChanging và OnChanged, đặc biệt là tham số nullable oldValue; hoàn tất khi cả hai dạng khớp nhau và không có CS8826.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug :bug:
Describe the bug

When decorating a property of a reference or otherwise nullable type with [ObservableProperty] the two-argument partial property-changing and property-changed method prototypes are generated differently than for decorated fields, not considering that the oldValue argument may be null.

Regression

No response

Steps to reproduce
  1. Create a new project targeting .NET 9.0 and depending on CommunityToolkit.Mvvm
  2. Create a class inheriting from ObservableObject
  3. Add the following code to the class:
    [ObservableProperty]
    private object _testA;
    
    [ObservableProperty]
    public object TestB { get; set; }
    
    partial void OnTestAChanged(object? oldValue, object newValue) { /* do nothing */ }
    
    partial void OnTestBChanged(object? oldValue, object newValue) { /* do nothing */ }
    
  4. Note that OnTestBChanged has warning CS8826 on it, because the generated partial declaration is partial void OnTestBChanged(global::System.Object oldValue, global::System.Object newValue); but there's no such warning for OnTestAChanged.
Expected behavior

The OnChanging(oldValue,newValue) and OnChanged(oldValue,newValue) partial method declarations for properties decorated with ObservablePropertyAttribute will be generated the same as for fields decorated with same.

Screenshots

No response

IDE and version

VS 2022

IDE version

17.14.9

Nuget packages
  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)

8.4.0

Additional context

The oldValue argument should always be generated as nullable for reference types as the initial call to the methods may be due to setting the property in the constructor (e.g. initial value may be based on a constructor argument, or the change methods may be used to set up and remove event handlers on the property value).

Help us help you

No, just wanted to report this

Ngôn ngữ chính
C#
Star
3.8k
Fork
402
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CommunityToolkit/dotnet

Tất cả issue của CommunityToolkit/dotnet

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.