`Command` class violates design rule CA1010
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
Hướng nghiên cứu
Bắt đầu từ khai báo được liên kết trong src/System.CommandLine/Command.cs và tái hiện CA1010 với AnalysisMode được đặt thành Recommended hoặc All bằng cách sử dụng ví dụ MyCommand. Hoàn thành nghĩa là các command kế thừa công khai không còn phát ra CA1010, đồng thời vẫn giữ nguyên hành vi hiện có của các phần tử con của Command.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
The System.CommandLine.Command class implements non-generic IEnumerable, but it does not implement IEnumerable<T>.
This causes classes inheriting from the Command class to violate design rule CA1010.
For projects with AnalysisMode set to Recommended or All, warning CA1010 will occur.
Build succeeded.
/home/smdn/temp/cli/Lib.cs(5,14): warning CA1010: Type 'MyCommand' directly or indirectly inherits 'IEnumerable' without implementing 'IEnumerable<T>'. Publicly-visible types should implement the generic version to broaden usability. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1010) [/home/smdn/temp/cli/cli.csproj]
1 Warning(s)
0 Error(s)
This simply triggers a warning and does not corrupt any functionality of System.CommandLine.
However, since the cause of the warning is not easy to find out and it may cause confusion, so I think this should be fixed.
Steps to reproduce
Set AnalysisMode to Recommended or All in the csproj file.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!-- Enable design rules including CA1010 -->
<AnalysisMode>Recommended</AnalysisMode>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.1" />
</ItemGroup>
</Project>
Create a class that inherits from the Command class.
using System.CommandLine;
namespace MyLibrary;
// warning CA1010: Type 'MyCommand' directly or indirectly inherits 'IEnumerable' without implementing 'IEnumerable<T>'. Publicly-visible types should implement the generic version to broaden usability. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1010)
public class MyCommand(string name, string? description) : Command(name, description) { }
Workarounds
The following workarounds are available to avoid this warning.
Workaround 1: disable warning CA1010
#pragma warning disable CA1010
public class MyCommand(string name, string? description) : Command(name, description)
{
}
#pragma warning restore CA1010
Workaround 2: implement IEnumerator<Symbol>
public class MyCommand(string name, string? description) : Command(name, description)
{
// Implement IEnumerator<Symbol> in order to suppress warning CA1010.
public IEnumerator<Symbol> GetEnumerator() => Children.GetEnumerator();
}
Workaround 3: reduce AnalysisMode
<!-- Reduce `AnalysisMode` to either `None`, `Default`, or `Minimum`. -->
<AnalysisMode>Minimum</AnalysisMode>
- Ngôn ngữ chính
- C#
- Star
- 3.7k
- Fork
- 434
- Merge trung bình
- 4 giờ 46 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/command-line-api
-
German localization is incompleteCó thể đã có người làm @b-v-d-e-v đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/command-line-api#2852 ·
-
Incomplete French (fr) translation: RequiredOptionWasNotProvided not translatedCó thể đã có người làm @JPBlanc đã nhận 105 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
dotnet/command-line-api#2822 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
dotnet/command-line-api#2792 · 2 bình luận · 16 reaction ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
dotnet/command-line-api#2704 ·
-
GetCompletions should check exit code of invoked applicationCó thể đã có người làm @baradgur đã nhận 1276 ngày trước. Đang mởArea-Completions bug help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
dotnet/command-line-api#2137 · 1 bình luận · 3 reaction ·
Tất cả issue của dotnet/command-line-api
Issue tương tự
-
[i18n] 安装实例完成后的成功提示未正确本地化Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
PCL-Community/PCL-CE#3658 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Deploy & Patch-issues opprettes ikke: create-pnd-issues.yml har feilet hver uke siden 2025-09-08Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Altinn/altinn-auth#4359 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
type/automation type/tech-debt
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
High-DPI fixes for release/1.3: editor toolbar icons and Color Picker layout (patch included)Đang mởno-stack-trace
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
S: Untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
project-wayfarer/wayfarer-14#1650 ·
Maintainer thường phản hồi trong vòng 2 ngày