1+ using System ;
2+ using System . CodeDom ;
3+ using System . Collections . Generic ;
4+ using System . Linq ;
5+
6+ namespace ProgramArgumentsManager
7+ {
8+ public class ArgumentsManager
9+ {
10+ public string ApplicationName { get ; }
11+ public string Version { get ; }
12+
13+ private Dictionary < Argument , string > _options ;
14+
15+ public ArgumentsManager ( string name ) : this ( name , "1.0.0" ) { }
16+
17+ public ArgumentsManager ( string name , string version )
18+ {
19+ ApplicationName = name ;
20+ Version = version ;
21+
22+ _options = new Dictionary < Argument , string > ( ) ;
23+ }
24+
25+ public void AddArguments ( string format , string description )
26+ {
27+ format = format . Trim ( ) ;
28+
29+ if ( ! format . Contains ( "-" ) && ! format . Contains ( "--" ) )
30+ throw new ArgumentException ( "Le format '" + format + " n'est pas comaptible en tant que paramètre !" ,
31+ nameof ( format ) ) ;
32+
33+ char [ ] delimiters = { ',' , ';' } ;
34+ string [ ] formats = format . Split ( delimiters ) ;
35+
36+ if ( formats . Any ( f => ! f . StartsWith ( "-" ) && ! f . StartsWith ( "--" ) ) )
37+ throw new ArgumentException ( "Le format '" + format + " n'est pas comaptible en tant que paramètre !" ,
38+ nameof ( format ) ) ;
39+
40+ _options . Add ( new Argument ( formats ) , description ) ;
41+ }
42+
43+ private class Argument
44+ {
45+ private string [ ] _names { get ; }
46+
47+ public Argument ( string name ) : this ( new [ ] { name } ) { }
48+ public Argument ( string name1 , string name2 ) : this ( new [ ] { name1 , name2 } ) { }
49+ public Argument ( string [ ] names )
50+ {
51+ _names = names ;
52+ }
53+
54+ public bool Contain ( string name ) => _names . Contains ( name ) ;
55+ }
56+ }
57+ }
0 commit comments