Penguins-lab.Cargs の使い方。
Cargsとは
まず、Cargsについてですね。
Cargsってのは、私の作った .Net Framework向けコマンドラインパーサ?です。
C#で利用できるコマンドラインパーサだと ”Command Line Parser Library” なんかがありますが・・・
これって、"/"で始まるswitchは解析できないんですよね。
ただそれだけの理由で、作ったものです。
内部処理からして全部フルスクラッチしたせいで、不具合多しバグ多しなパッケージです。
ですが、何故か1日に8件とかのペースでDLされてるんですよね。(2017/11/28現在)
恐らく、DLした人は使い方がわからずそのまま削除してると思うんで、多少なり使い方の説明をしてる場所があっても良いのかな?と思った次第です。
導入
Visual Studio 2017 を使用して説明します。
[ソリューションエクスプローラー] > [プロジェクト] > [NuGetパッケージの管理(N)...]
出てきた、"Penguins-lab.Cargs"をインストールします。
使い方
以下のソースコードをご覧ください。
using Cargs.Attributes; namespace ConsoleApp1 { class Program { //短いswitch名と長いswitch名を指定できます。 // /a // /prop1 [PropSwitch( 'a', "prop1" )] public bool HogeProp1 { get; set; } //長いswitch名だけでも // /prop2 [PropSwitch( "prop2" )] public bool HogeProp2 { get; set; } //もちろん短いswitch名だけでもOK // /p [PropSwitch( 'p' )] public bool HogeProp3 { get; set; } // 文字列が欲しい場合 // /prop4 hogehoge [PropSwitch( "prop4", Option = SwitchOptions.String )] public string HogeProp4 { get; set; } //staticでも動作します。 // /prop5 [PropSwitch( "prop5" )] public static bool HogeProp5 { get; set; } //こちらもPropertyと同じように指定できます // /b // /Method1 [MethodSwitch( 'b', "Method1" )] public void HogeMethod1() { } //引数を持つこともできます // /Method2 123 hoge [MethodSwitch( "Method2", SwitchOptions.Int, SwitchOptions.String )] public void HogeMethod2( int i, string s) { } //もちろんstaticでも動作します。 // /Method3 [MethodSwitch( "Method3" )] public static void HogeMethod3() { } static void Main(string[] args) { var ins = new Program(); //引数の解析をします Cargs.Analyzer.Analyze( ins, args ); } } }
以上のサンプルで、だいたい使い方は分かって頂けましたか・・・?
少し、投げやり過ぎる気はしますが、許して下さい。
はじめの、
using Cargs.Attributes;
を追加するのをお忘れなく。