Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Double generic types and members with non-generic equivalents

オープン
#2,757 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp
領域
cli

調査の方向性

まず、既存のジェネリックな ParseResult.GetValue API と Option コンストラクターを確認し、提案されている Type ベースのオーバーロードを対象範囲とします。次に、このパターンを非ジェネリックな DI API と比較し、そのうえで、代替案が示されているリフレクションフリーな AOT のユースケースをサポートしつつ、ジェネリックな動作を維持できることを検証します。

索引モデルが issue の本文から書いたものです。

説明

Examples

// In addition to these:
T? ParseResult.GetValue<T>(Option<T> option);
new Option<T>(string name, params string[] aliases);
// etc...

// Make it possible to call them like this:
object? ParseResult.GetValue(Option option, Type valueType);
new Option(Type valueType, string name, params string[] aliases);

This is somewhat similar to what we have in DI:

// We can add service like this:
services.AddSignleton<T>();

// Or this:
services.AddSingleton(Type serviceType);

Justification

I am making my own library that adds proper hosting API, making using System.CommandLine similar to any regular ASP.NET project.
For example:

Program.cs

app.MapCommand("foo", ([Option] FileInfo file) =>
{
    foreach (string line in File.ReadLines(file.FullName))
        Console.WriteLine(line);
});

ShellApplication.cs

public void MapCommand(string name, Delegate command)
{
	RootCommand rootCommand = [];
	ParameterInfo[] parameters = command.Method.GetParameters();

	foreach (ParameterInfo parameterInfo in parameters)
	{
		if (parameterInfo.GetCustomAttribute<OptionAttribute>() is not null)
		{
			Option option = (typeof(Option<>).MakeGenericType(parameterInfo.ParameterType).GetConstructor([typeof(string), typeof(string[])])!.Invoke([name]) as Option)!;
			rootCommand.Options.Add(option);
		}
	}
	// etc...
}

At first glance this looks fine – just make a generic type using reflection. Only the problem is that this is not AOT compatible and will cause exceptions. Adding alternatives that accept types as parameters would solve this.

Additional context

I've glossed over the codebase, and it doesn't look like it will be that hard to implement changes. If that's ok with you, I can prepare a PR myself.

主要言語
C#
スター
3.7k
フォーク
434
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dotnet/command-line-api のほかの issue

dotnet/command-line-api の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。