11using Microsoft . CodeAnalysis ;
2- using System ;
3- using System . Data . Common ;
4- using System . Diagnostics . CodeAnalysis ;
5- using System . Reflection ;
6- using System . Reflection . Metadata ;
72using System . Text ;
83
94namespace ConsoleAppFramework ;
@@ -24,16 +19,16 @@ public record class Command
2419{
2520 public required bool IsAsync { get ; init ; } // Task or Task<int>
2621 public required bool IsVoid { get ; init ; } // void or int
27-
22+
2823 public bool IsRootCommand => Name == "" ;
2924 public required string Name { get ; init ; }
3025
31- public required CommandParameter [ ] Parameters { get ; init ; }
26+ public required EquatableArray < CommandParameter > Parameters { get ; init ; }
3227 public required string Description { get ; init ; }
3328 public required MethodKind MethodKind { get ; init ; }
3429 public required DelegateBuildType DelegateBuildType { get ; init ; }
3530 public CommandMethodInfo ? CommandMethodInfo { get ; set ; } // can set...!
36- public required FilterInfo [ ] Filters { get ; init ; }
31+ public required EquatableArray < FilterInfo > Filters { get ; init ; }
3732 public bool HasFilter => Filters . Length != 0 ;
3833
3934 public string ? BuildDelegateSignature ( out string ? delegateType )
@@ -148,15 +143,16 @@ public string BuildDelegateType(string delegateName)
148143
149144public record class CommandParameter
150145{
151- public required ITypeSymbol Type { get ; init ; }
152- public required Location Location { get ; init ; }
146+ public required EquatableTypeSymbol Type { get ; init ; }
147+ public required IgnoreEquality < Location > Location { get ; init ; }
148+ public required IgnoreEquality < WellKnownTypes > WellKnownTypes { get ; init ; }
153149 public required bool IsNullableReference { get ; init ; }
154150 public required bool IsParams { get ; init ; }
155151 public required string Name { get ; init ; }
156152 public required string OriginalParameterName { get ; init ; }
157153 public required bool HasDefaultValue { get ; init ; }
158154 public object ? DefaultValue { get ; init ; }
159- public required ITypeSymbol ? CustomParserType { get ; init ; }
155+ public required EquatableTypeSymbol ? CustomParserType { get ; init ; }
160156 public required bool IsFromServices { get ; init ; }
161157 public required bool IsConsoleAppContext { get ; init ; }
162158 public required bool IsCancellationToken { get ; init ; }
@@ -165,15 +161,15 @@ public record class CommandParameter
165161 public required bool HasValidation { get ; init ; }
166162 public required int ArgumentIndex { get ; init ; } // -1 is not Argument, other than marked as [Argument]
167163 public bool IsArgument => ArgumentIndex != - 1 ;
168- public required string [ ] Aliases { get ; init ; }
164+ public required EquatableArray < string > Aliases { get ; init ; }
169165 public required string Description { get ; init ; }
170166 public bool RequireCheckArgumentParsed => ! ( HasDefaultValue || IsParams || IsFlag ) ;
171167
172168 // increment = false when passed from [Argument]
173- public string BuildParseMethod ( int argCount , string argumentName , WellKnownTypes wellKnownTypes , bool increment )
169+ public string BuildParseMethod ( int argCount , string argumentName , bool increment )
174170 {
175171 var incrementIndex = increment ? "!TryIncrementIndex(ref i, args.Length) || " : "" ;
176- return Core ( Type , false ) ;
172+ return Core ( Type . TypeSymbol , false ) ;
177173
178174 string Core ( ITypeSymbol type , bool nullable )
179175 {
@@ -207,7 +203,7 @@ string Core(ITypeSymbol type, bool nullable)
207203 {
208204 return $ "arg{ argCount } = args[i];";
209205 }
210-
206+
211207 case SpecialType . System_Boolean :
212208 return $ "arg{ argCount } = true;"; // bool is true flag
213209 case SpecialType . System_Char :
@@ -242,7 +238,7 @@ string Core(ITypeSymbol type, bool nullable)
242238 if ( type . TypeKind == TypeKind . Array )
243239 {
244240 var elementType = ( type as IArrayTypeSymbol ) ! . ElementType ;
245- var parsable = wellKnownTypes . ISpanParsable ;
241+ var parsable = WellKnownTypes . Value . ISpanParsable ;
246242 if ( parsable != null ) // has parsable
247243 {
248244 if ( elementType . AllInterfaces . Any ( x => x . EqualsUnconstructedGenericType ( parsable ) ) )
@@ -254,12 +250,12 @@ string Core(ITypeSymbol type, bool nullable)
254250 }
255251
256252 // System.DateTimeOffset, System.Guid, System.Version
257- tryParseKnownPrimitive = wellKnownTypes . HasTryParse ( type ) ;
253+ tryParseKnownPrimitive = WellKnownTypes . Value . HasTryParse ( type ) ;
258254
259255 if ( ! tryParseKnownPrimitive )
260256 {
261257 // ISpanParsable<T> (BigInteger, Complex, Half, Int128, etc...)
262- var parsable = wellKnownTypes . ISpanParsable ;
258+ var parsable = WellKnownTypes . Value . ISpanParsable ;
263259 if ( parsable != null ) // has parsable
264260 {
265261 tryParseIParsable = type . AllInterfaces . Any ( x => x . EqualsUnconstructedGenericType ( parsable ) ) ;
@@ -316,13 +312,6 @@ public string DefaultValueToString(bool castValue = true, bool enumIncludeTypeNa
316312 return $ "({ Type . ToFullyQualifiedFormatDisplayString ( ) } ){ DefaultValue } ";
317313 }
318314
319- public string ? GetEnumSymbolName ( object value )
320- {
321- var symbol = Type . GetMembers ( ) . OfType < IFieldSymbol > ( ) . FirstOrDefault ( x => x . ConstantValue == value ) ;
322- if ( symbol == null ) return "" ;
323- return symbol . Name ;
324- }
325-
326315 public string ToTypeDisplayString ( )
327316 {
328317 var t = Type . ToFullyQualifiedFormatDisplayString ( ) ;
@@ -359,7 +348,7 @@ public record class CommandMethodInfo
359348{
360349 public required string TypeFullName { get ; init ; }
361350 public required string MethodName { get ; init ; }
362- public required ITypeSymbol [ ] ConstructorParameterTypes { get ; init ; }
351+ public required EquatableArray < EquatableTypeSymbol > ConstructorParameterTypes { get ; init ; }
363352 public required bool IsIDisposable { get ; init ; }
364353 public required bool IsIAsyncDisposable { get ; init ; }
365354
@@ -378,7 +367,7 @@ public string BuildNew()
378367public record class FilterInfo
379368{
380369 public required string TypeFullName { get ; init ; }
381- public required ITypeSymbol [ ] ConstructorParameterTypes { get ; init ; }
370+ public required EquatableArray < EquatableTypeSymbol > ConstructorParameterTypes { get ; init ; }
382371
383372 FilterInfo ( )
384373 {
@@ -400,7 +389,7 @@ public record class FilterInfo
400389 var filter = new FilterInfo
401390 {
402391 TypeFullName = type . ToFullyQualifiedFormatDisplayString ( ) ,
403- ConstructorParameterTypes = publicConstructors [ 0 ] . Parameters . Select ( x => x . Type ) . ToArray ( )
392+ ConstructorParameterTypes = publicConstructors [ 0 ] . Parameters . Select ( x => new EquatableTypeSymbol ( x . Type ) ) . ToArray ( )
404393 } ;
405394
406395 return filter ;
0 commit comments