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

Unable to map classes with generics

Đang mở
#724 1 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
tooling

Hướng nghiên cứu

Không có tệp, kiểm thử hoặc entry point nào được nêu. Hãy bắt đầu bằng cách tái hiện các lỗi lúc biên dịch và lúc runtime đã báo cáo bằng Audit, các lớp con của LogData, DTO, Include và các cấu hình IgnoreNonMapped được mô tả ở đây; được xem là hoàn tất khi hành vi mong đợi và một bản sửa tập trung đã được xác lập cho cả hai trường hợp mapping generic.

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

Mô tả

configuration problem

I would want to map a class structure for logs. The main class is a generic class Audit<T> where T is class LogData or a subclass it.
DTO would have a simple structure with AuditDTO and property of type LogDataDTO, that object has all the possible subclass properties united in it.

  • My initial issues occurred at compile time as CompileException .
    If my configuration has
    config.NewConfig<LogData, LogDataDTO>() <-- with all base class properties mapped plus
    .IgnoreNonMapped(true)
    .Include<LogDataSubclass, LogDataDTO>() <-- for all subclass of LogData

and
config.NewConfig<LogDataSubclass, LogDataDTO>() <-- with all the specific subclass properties mapped plus
.IgnoreNonMapped(true)

then it would complain about LogDataDTO not having a corresponding source member mapped or ignored: SOME properties of LogDataSubclasses' - but weird enough not all of them. If I added to the LogData baseclass config explicitly the .Ignore(dest => dest.ProblematicSubclassProp) then that would solve the issue.

  • Second issue occurred afterward at runtime. The AuditDTO had the same exception that its properties, other than the LogData, are not mapped or ignored. Adding an explicit config for mapping seems trickier as it does not seem to work with invariance:
    if there's config.NewConfig<Audit<LogData>(), AuditDTO>(), or any other type of <Audit<LogDataSubclass>, AuditDTO> then the source type causing the error is referred to as <IAudit<ILogData>>. (Conventional interfaces)

I have the impression that i heavily overcomplicate the config and not using (misusing) some methods here... IgnoreNonMapped is definetely not working as expected and makes this whole declarartion redundant.

Ngôn ngữ chính
C#
Star
5.2k
Fork
411
Merge trung bình
3 ngày 4 giờ
Pull request đã merge (30 ngày)
3

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 MapsterMapper/Mapster

Tất cả issue của MapsterMapper/Mapster

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.