@@ -172,6 +172,114 @@ internal class Parser(ConsoleAppFrameworkGeneratorOptions generatorOptions, Diag
172172 . ToArray ( ) ;
173173 }
174174
175+ public void ParseGlobalOptions ( )
176+ {
177+
178+ // GlobalOptions allow type is limited. see ConsoleAppBaseCode.TryParse
179+ bool IsParsableType ( ITypeSymbol type , Compilation compilation , WellKnownTypes wellKnownTypes )
180+ {
181+ if ( type is INamedTypeSymbol { IsValueType : true , OriginalDefinition . SpecialType : SpecialType . System_Nullable_T } namedType )
182+ {
183+ return false ;
184+ }
185+
186+ switch ( type . SpecialType )
187+ {
188+ case SpecialType . System_String :
189+ case SpecialType . System_Char :
190+ case SpecialType . System_SByte :
191+ case SpecialType . System_Byte :
192+ case SpecialType . System_Int16 :
193+ case SpecialType . System_UInt16 :
194+ case SpecialType . System_Int32 :
195+ case SpecialType . System_UInt32 :
196+ case SpecialType . System_Int64 :
197+ case SpecialType . System_UInt64 :
198+ case SpecialType . System_Single :
199+ case SpecialType . System_Double :
200+ case SpecialType . System_Decimal :
201+ return true ;
202+ }
203+
204+ if ( type . TypeKind == TypeKind . Enum )
205+ {
206+ return true ;
207+ }
208+
209+ var comparer = SymbolEqualityComparer . Default ;
210+ if ( comparer . Equals ( type , wellKnownTypes . Guid ) ) return true ;
211+ if ( comparer . Equals ( type , wellKnownTypes . DateTime ) ) return true ;
212+ if ( comparer . Equals ( type , wellKnownTypes . DateTimeOffset ) ) return true ;
213+ if ( comparer . Equals ( type , wellKnownTypes . TimeOnly ) ) return true ;
214+ if ( comparer . Equals ( type , wellKnownTypes . DateOnly ) ) return true ;
215+ if ( comparer . Equals ( type , wellKnownTypes . Version ) ) return true ;
216+
217+ return false ;
218+ }
219+
220+ object ? GetDefaultValue ( ITypeSymbol type )
221+ {
222+ if ( type is INamedTypeSymbol { IsValueType : true , OriginalDefinition . SpecialType : SpecialType . System_Nullable_T } namedType )
223+ {
224+ return null ;
225+ }
226+
227+ if ( type . TypeKind == TypeKind . Enum )
228+ {
229+ var enumType = ( INamedTypeSymbol ) type ;
230+ var underlyingType = enumType . EnumUnderlyingType ;
231+ return underlyingType ? . SpecialType switch
232+ {
233+ SpecialType . System_Byte => ( byte ) 0 ,
234+ SpecialType . System_SByte => ( sbyte ) 0 ,
235+ SpecialType . System_Int16 => ( short ) 0 ,
236+ SpecialType . System_UInt16 => ( ushort ) 0 ,
237+ SpecialType . System_Int32 => 0 ,
238+ SpecialType . System_UInt32 => 0u ,
239+ SpecialType . System_Int64 => 0L ,
240+ SpecialType . System_UInt64 => 0UL ,
241+ _ => 0
242+ } ;
243+ }
244+
245+ var fullName = type . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ;
246+ switch ( fullName )
247+ {
248+ case "global::System.DateTime" :
249+ return default ( DateTime ) ; // new DateTime(0)
250+ case "global::System.DateTimeOffset" :
251+ return default ( DateTimeOffset ) ;
252+ case "global::System.TimeSpan" :
253+ return default ( TimeSpan ) ;
254+ case "global::System.Guid" :
255+ return default ( Guid ) ; // Guid.Empty
256+ //case "global::System.DateOnly":
257+ // return default(DateOnly);
258+ //case "global::System.TimeOnly":
259+ // return default(TimeOnly);
260+ }
261+
262+ switch ( type . SpecialType )
263+ {
264+ case SpecialType . System_Boolean : return false ;
265+ case SpecialType . System_Byte : return ( byte ) 0 ;
266+ case SpecialType . System_SByte : return ( sbyte ) 0 ;
267+ case SpecialType . System_Int16 : return ( short ) 0 ;
268+ case SpecialType . System_UInt16 : return ( ushort ) 0 ;
269+ case SpecialType . System_Int32 : return 0 ;
270+ case SpecialType . System_UInt32 : return 0u ;
271+ case SpecialType . System_Int64 : return 0L ;
272+ case SpecialType . System_UInt64 : return 0UL ;
273+ case SpecialType . System_Single : return 0f ;
274+ case SpecialType . System_Double : return 0d ;
275+ case SpecialType . System_Decimal : return 0m ;
276+ case SpecialType . System_Char : return '\0 ' ;
277+ default :
278+ return null ;
279+ }
280+ }
281+ }
282+
175283 Command ? ExpressionToCommand ( ExpressionSyntax expression , string commandName )
176284 {
177285 var lambda = expression as ParenthesizedLambdaExpressionSyntax ;
0 commit comments