11using System ;
2- using System . CodeDom ;
32using System . Collections . Generic ;
43using System . Linq ;
54
@@ -24,8 +23,8 @@ public ArgumentsManager(string name, string version)
2423
2524 public void AddArguments ( string format , string description )
2625 {
27- format = format . Trim ( ) ;
28-
26+ format = format . Replace ( " " , string . Empty ) ;
27+
2928 if ( ! format . Contains ( "-" ) && ! format . Contains ( "--" ) )
3029 throw new ArgumentException ( "Le format '" + format + " n'est pas comaptible en tant que paramètre !" ,
3130 nameof ( format ) ) ;
@@ -42,16 +41,40 @@ public void AddArguments(string format, string description)
4241
4342 private class Argument
4443 {
45- private string [ ] _names { get ; }
44+ private readonly string [ ] _names ;
4645
47- public Argument ( string name ) : this ( new [ ] { name } ) { }
48- public Argument ( string name1 , string name2 ) : this ( new [ ] { name1 , name2 } ) { }
4946 public Argument ( string [ ] names )
5047 {
5148 _names = names ;
5249 }
5350
54- public bool Contain ( string name ) => _names . Contains ( name ) ;
51+ private bool Equals ( Argument other ) => other . _names . Any ( s => _names . Contains ( s ) ) ;
52+
53+ public override bool Equals ( object obj )
54+ {
55+ if ( obj is null )
56+ return false ;
57+ if ( ReferenceEquals ( this , obj ) )
58+ return true ;
59+
60+ return obj . GetType ( ) == GetType ( ) && Equals ( ( Argument ) obj ) ;
61+ }
62+
63+ public override int GetHashCode ( )
64+ {
65+ // Same HashCode for each instance to force the use of the Equals method (for the Dictionnary key)
66+ return 0 ;
67+ }
68+
69+ public static bool operator == ( Argument left , Argument right )
70+ {
71+ return Equals ( left , right ) ;
72+ }
73+
74+ public static bool operator != ( Argument left , Argument right )
75+ {
76+ return ! Equals ( left , right ) ;
77+ }
5578 }
5679 }
5780}
0 commit comments