commandlineparser / commandlineparser/commandline
Consider custom parsers/converters/handler for types?
- 主要言語
- C#
- スター
- 4.8k
- フォーク
- 478
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I would love to be able to do:
```c#
public class Options
{
[Option('o', "out", Required = true, HelpText = "Output file")]
public string OutFile { get; set; }
[Option('d', "duration", Required = false, Default = "1:00:00", HelpText = "Duration")]
public TimeSpan Duration { get; set; }
[Option('e', "endpoint", Required = true, HelpText = "IP Endpoint (:)")]
public IPEndPoint Endpoint { get; set; }
}
```
Where I can use types like `TimeSpan` and `IPEndPoint` or any other type. Ofcourse, we would need to be able to specify a parser/converter/handler/whatever that takes the value and converts it to the desired type. I imagine it be like:
```c#
public class Options
{
[Option('o', "out", Required = true, HelpText = "Output file")]
public string OutFile { get; set; }
[Option('d', "duration", Required = false, Default = "1:00:00", HelpText = "Duration", Converter = typeof(MyTimeSpanConverter))]
public TimeSpan Duration { get; set; }
[Option('e', "endpoint", Required = true, HelpText = "IP Endpoint (:)", Converter = typeof(MyIPEndpointConverter))]
public IPEndPoint Endpoint { get; set; }
}
```
Next these 'converters' should implement something like an IConvert that defines a method `T Convert(string value)` where they take a string (the commandline argument) and convert to the desired type. Another option would be to not use the attributes but be able to specify handlers like:
```c#
Parser.Default
.Register()
.Register()
.ParseArguments(args)
....
```
Would that be something that you would consider? (Maybe not exactly following the idea given above, but the broader idea of being able to handle custom types).
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
実装ファイルやテストは指定されていません。Parser.Default と ParseArguments から始め、現在オプション文字列がどのように変換されているかを追跡し、提案されている属性ベースの Converter と登録のアプローチを比較してください。TimeSpan や IPEndPoint などのカスタム型を、確定してテスト済みの API を通じて処理できるようになれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- csharp
- 領域
- cli
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100