How can I assign TypeConverter to Enum in `Options`?
まだ誰も着手していません。
評価
調査の方向性
Options.Operation プロパティと TypeDescriptor.AddAttributes 呼び出しから始め、コマンドライン パーサーの変換経路を追跡して、プロパティ レベルまたは enum レベルのコンバーターが使用されているかどうかを判断します。完了条件は、カスタム コンバーターが cd を Operation.CreateDirectory にマッピングするように、サポートされている登録経路を文書化または修正することです。
索引モデルが issue の本文から書いたものです。
説明
I've declared Options which will be used for parsing command line.
public class Options {
// ...
[Option('o', "operation", HelpText = "")]
[TypeConverter(typeof(OperationConverter))]
public Operation Operation { get; set; }
}
And the Operation looks like this:
[TypeConverter(typeof(OperationConverter))]
public enum Operation {
// ...
CreateDirectory,
// ...
}
Since CreateDirectory is quite long to type in command line, I want to allow cd as valid Operation.CreateDirectory
public class OperationConverter : EnumConverter {
// ... candidates for other enum values
private static readonly List<string> OperationCandidate = ["createdirectory", "cd"];
// ...
public override object ConvertFrom(ITypeDescriptorContext? ctx, CultureInfo? ci, object value) {
if (value is string s) {
string l = s.Trim().ToLowerInvariant();
// ...
if (OperationCandidate.Contains(l)) return Operation.CreateDirectory;
// ...
}
}
}
But I can't assign this OperationConverter to Options.Operation. I don't see anything that might be related to this.
#83 says it is resolved, but at the bottom of that issue, someone said:
I dont think this works in the latest version. I tried annotating my option's property, but the converter is not invoked. Instead I had to register it using
TypeDescriptor.AddAttributes().
But I don't see any methods named .AddAttributes() in TypeDescriptor. this has .AddAttributes(), but this doesn't seem to work.
private static void Main(string[] args) {
// ...
TypeDescriptor.AddAttributes(typeof(Operation), new TypeConverterAttribute(typeof(OperationConverter)));
// other logic + command line parsing
}
Now I'm completely lost. Wiki doesn't provide any useful information that I can easily access.
How can I assign TypeConverter to Enum in Options?
- 主要言語
- C#
- スター
- 4.8k
- フォーク
- 478
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
commandlineparser/commandline のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
commandlineparser/commandline#951 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 70/100
commandlineparser/commandline#880 · リアクション 2 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
commandlineparser/commandline#952 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
commandlineparser/commandline#948 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
commandlineparser/commandline#947 ·
commandlineparser/commandline の issue をすべて見る
似ている issue
-
bug frontend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
NavigationViewItemAutomationPeer implements IInvokeProvider but never advertises the Invoke pattern オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
unoplatform/uno#24629 ·
-
agentic-workflows Needs: Triage :mag: State: In-PR
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
Type: enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
apache/arrow-adbc#4809 ·