Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Allow ObservableObject/INotifyPropertyChanged generator to work with interface specified

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

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá 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

Tái hiện trường hợp WinUI bằng cách sử dụng [ObservableObject] hoặc [INotifyPropertyChanged] với một interface được khai báo rõ ràng và quan sát các cảnh báo MVVMTK0049/0050. Bắt đầu bằng cách theo dõi cách generator xử lý các interface do người dùng khai báo, sau đó xác minh rằng implementation được sinh vẫn khả dụng và các cảnh báo AOT đã được giải quyết, bao gồm cả workaround cho việc kế thừa kiểu trừu tượng.

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

Mô tả

Currently, using [ObservableObject]/[INotifyPropertyChanged] generator in WinUI project causes warning MVVMTK0049/0050, since WinRT source generator can't see the implemented interface in MVVMTK source generator.

A workaround for this can be explicitly specify the interfaces in user written part, then they are visible to WInRT source generator:

[INotifyPropertyChanged]
public abstract partial class MyControlBase : UserControl, INotifyPropertyChanged
{
}

However, when the MVVMTK generator sees the interface specification, it will think the interface is implemented by user and remove its generation. If we can force it to provide its generation, then the AOT warning should be addressed.


I also find a workaround by introducing another level of inheritance:

[INotifyPropertyChanged]
public abstract partial class ObservableUserControl : UserControl
{
}

public partial class MyControl : ObservableUserControl, INotifyPropertyChanged

Then WinRT source generator will correctly see interfaces on MyControl, only ObservableUserControl is missing the interface info. Is it safe to ignore the warnings for abstract types?

Ngôn ngữ chính
C#
Star
3.8k
Fork
401
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.