Double generic types and members with non-generic equivalents
まだ誰も着手していません。
評価
調査の方向性
まず、既存のジェネリックな 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 はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
dotnet/command-line-api のほかの issue
-
German localization is incomplete対応中かも @b-v-d-e-v が 7 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
dotnet/command-line-api#2852 ·
-
Incomplete French (fr) translation: RequiredOptionWasNotProvided not translated対応中かも @JPBlanc が 104 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
dotnet/command-line-api#2822 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
dotnet/command-line-api#2792 · コメント 2 件 · リアクション 15 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
dotnet/command-line-api#2704 ·
-
GetCompletions should check exit code of invoked application対応中かも @baradgur が 1276 日前に担当しました。 オープンArea-Completions bug help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
dotnet/command-line-api#2137 · コメント 1 件 · リアクション 3 件 ·
dotnet/command-line-api の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
stryker-mutator/stryker-net#3892 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
MobiFlight/MobiFlight-Connector#3419 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Kryptos-FR/MarkView.Avalonia#105 ·
メンテナーはふだん 1 日以内に返信
-
[辞書]オープン提案 辞書
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
microsoft/fluentui-blazor#5410 ·
メンテナーはふだん 1 日以内に返信