`Command` class violates design rule CA1010
まだ誰も着手していません。
評価
調査の方向性
src/System.CommandLine/Command.cs のリンクされた宣言から始め、MyCommand の例を使用して、AnalysisMode を Recommended または All に設定した状態で CA1010 を再現します。公開継承するコマンドが CA1010 を出力しなくなり、既存の Command の子要素の動作が維持されていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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>
- 主要言語
- C#
- スター
- 3.7k
- フォーク
- 434
- 平均マージ
- 4時間 46分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/command-line-api のほかの issue
-
German localization is incomplete対応中かも @b-v-d-e-v が 8 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
dotnet/command-line-api#2852 ·
-
Incomplete French (fr) translation: RequiredOptionWasNotProvided not translated対応中かも @JPBlanc が 106 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
dotnet/command-line-api#2822 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
dotnet/command-line-api#2792 · コメント 2 件 · リアクション 16 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
dotnet/command-line-api#2704 ·
-
GetCompletions should check exit code of invoked application対応中かも @baradgur が 1277 日前に担当しました。 オープンArea-Completions bug help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dotnet/command-line-api#2137 · コメント 1 件 · リアクション 3 件 ·
dotnet/command-line-api の issue をすべて見る
似ている issue
-
[Tool] DirectBenchオープンhas-image has-readme needs-attention new-tool repo-verified
難易度 1/5 1〜3時間 初心者へのやさしさ 62/100
shanselman/TinyToolTown#844 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
PCL-Community/PCL-CE#3658 ·
メンテナーはふだん 1 日以内に返信
-
Deploy & Patch-issues opprettes ikke: create-pnd-issues.yml har feilet hver uke siden 2025-09-08オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Altinn/altinn-auth#4359 ·
メンテナーはふだん 1 日以内に返信
-
アプリ: チャット 優先: 中 提案
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
yksr-melt/Meltype#243 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug core
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信