Pattern docs can be improved

Đang mở
#6,893 2 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ó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tài liệu
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
documentation

Hướng nghiên cứu

Xem xét các đường dẫn được liệt kê trong issue dưới samples\csharp\tutorials\patterns, đặc biệt là start\toll-calculator.csproj, finished\toll_calculator.csproj và ExternalSystems.cs. Bắt đầu bằng cách build các project start và finished để tái hiện các vấn đề về project và biên dịch đã được báo cáo. Công việc được xem là hoàn tất khi một tập con các thay đổi được đề xuất đối với tài liệu và mã mẫu đã được thống nhất, đồng thời các project bị ảnh hưởng build thành công.

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

Mô tả

Pattern docs at samples\csharp\tutorials\patterns can be improved ...

  1. the samples\csharp\tutorials\patterns\start\toll-calculator.csproj does not compile without TollCalculator implementation
  2. attempting to add samples\csharp\tutorials\patterns\finished\toll_calculator.csproj as shared project fails with duplicate project names
  3. changing project names [e.g. to Toll-start.csproj, Toll-finished.csproj] complains due to conflicting ExternalSystems
  4. classes in ExternalSystems.cs should have default properties or marked required [e.g. otherwise new DeliveryTruck() inits GrossWeightClass=0 !]
    although better to have explicit ctors with initializer for all props [maybe derive from external source to enforce]
  5. should be simplified to "public static class TollCalculator{..}" so don't need concrete tollCalc instance
  6. CalculateToll parameter should be nullable [i.e. public decimal CalculateToll(object? vehicle) => ...], and change calls from null! to null.
  7. perhaps fullVan and fullVanPool should be fullCar and fullTaxi respectively ("full van" a peculiarly American phrase)
    also "GrossWeightClass" -> "GrossWeight" since unit is lbs as int
  8. code is littered with magic numbers (e.g. variously as 2.00m or 2.0m) when should instead be defined in ONE place (e.g. as const decimal CarFare=2.00m)
  9. "The null pattern can be last because the other patterns match only a non-null object of the correct type." is non-optimal
    in switch expression the null check should happen once [first] otherwise each "is" typecast would have to perform its own null guard compare
  10. inefficient switch arms in CalculateToll for Bus, DeliveryTruck [repeated typecast executions]
  11. final (catch-all) arm [discard pattern] can be simplified to _ => [e.g. not (_, _, _)]
  12. IsWeekDay can be simplified
  13. PeakTimePremiumIfElse compares hour < 20 whereas GetTimeBand uses > 19 [needs more brain cycles to verify equivalence]
  14. need more vehicle types and/or catch-all [can't just declare unknown!]. e.g. see NYC CRZ at https://congestionreliefzone.mta.info/tolling
    practical to accurately assess GrossWeightClass without an actual weighbridge stop ?
  15. unnecessary subfolder hierarchy [e.g. simplify start/toll-calculator/* to start-calculator/*]
  16. should update TFM [i.e. "net6.0" to "net8.0"] on all projects

I am in process of crafting a PR to suggest how I think docs and sample code should look.

Ngôn ngữ chính
C#
Star
3.7k
Fork
5.1k
Merge trung bình
19 giờ 47 phút
Pull request đã merge (30 ngày)
2

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 dotnet/samples

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

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.