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

Generic IEnumerator not disposed

Đang mở
#667 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
45/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

Bắt đầu với Mapster.Tool và tái hiện phương thức mở rộng được sinh ra bằng cách sử dụng đăng ký NewConfig<TSource, TDestination>().GenerateMapper(...) được hiển thị. Kiểm tra đường dẫn sinh GetEnumerator(), bao gồm cả mã được sinh ra từ các interface nếu áp dụng; hoàn thành khi các enumerator generic được giải phóng trong quá trình lặp mà hành vi lặp vẫn không thay đổi.

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

Mô tả

improvement

I'm using Mapster.Tool to generate extension methods from my mapping registrations like so:

config.NewConfig<TSource, TDestination>().GenerateMapper(MapType.Map | MapType.MapToTarget);

When inspecting the generated code I noticed that anywhere GetEnumerator() is used, the generic Enumerator is never disposed.

This is a snippet of what is being generated:

...
IEnumerator<string> enumerator = p2.GetEnumerator();
            
while (enumerator.MoveNext())
 {
    string item = enumerator.Current;
    result.Add(item);
}

return result;

I believe what it should be generating is the following:

using IEnumerator<string> enumerator = p2.GetEnumerator();
            
while (enumerator.MoveNext())
 {
    string item = enumerator.Current;
    result.Add(item);
}

return result;

I'm not sure if this issue arises in other areas (e.g. generated code from interfaces) as I haven't tested it personally, but I would expect the Mapster.Tool generates the code the same way.

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