@@ -31,6 +31,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3131 static void EmitAttributes ( IncrementalGeneratorPostInitializationContext context )
3232 {
3333 context . AddSource ( "GenerateToonTabularArrayConverter.g.cs" , """
34+ // <auto-generated/>
35+ #pragma warning disable
36+ #nullable enable
37+
3438using System;
3539
3640namespace Cysharp.AI
@@ -60,14 +64,9 @@ static void EmitTabularArrayConverter(SourceProductionContext sourceProductionCo
6064 ToonPrimitiveKind . Boolean => $ "toonWriter.WriteBoolean(item.{ name } );",
6165 ToonPrimitiveKind . String => $ "toonWriter.WriteString(item.{ name } );",
6266 ToonPrimitiveKind . Number => $ "toonWriter.WriteNumber(item.{ name } );",
63- ToonPrimitiveKind . DateTime => $ "toonWriter.WriteString(item.{ name } );",
64- ToonPrimitiveKind . Guid => $ "toonWriter.WriteString(item.{ name } );",
65- ToonPrimitiveKind . Enum => $ "toonWriter.WriteString(item.{ name } );",
6667 ToonPrimitiveKind . NullableBoolean => $ "if (item.{ name } == null) {{ toonWriter.WriteNull(); }} else {{ toonWriter.WriteBoolean(item.{ name } ); }}",
6768 ToonPrimitiveKind . NullableNumber => $ "if (item.{ name } == null) {{ toonWriter.WriteNull(); }} else {{ toonWriter.WriteNumber(item.{ name } ); }}",
68- ToonPrimitiveKind . NullableDateTime => $ "if (item.{ name } == null) {{ toonWriter.WriteNull(); }} else {{ toonWriter.WriteString(item.{ name } ); }}",
69- ToonPrimitiveKind . NullableGuid => $ "if (item.{ name } == null) {{ toonWriter.WriteNull(); }} else {{ toonWriter.WriteString(item.{ name } ); }}",
70- ToonPrimitiveKind . NullableEnum => $ "if (item.{ name } == null) {{ toonWriter.WriteNull(); }} else {{ toonWriter.WriteString(item.{ name } ); }}",
69+ ToonPrimitiveKind . NullableString => $ "if (item.{ name } == null) {{ toonWriter.WriteNull(); }} else {{ toonWriter.WriteString(item.{ name } ); }}",
7170 _ => throw new NotSupportedException ( $ "Unsupported property type for Toon serialization: { kind } ") ,
7271 } ;
7372 return " " /* indent */ + str ;
@@ -223,20 +222,15 @@ static ToonPrimitiveKind GetKind(ITypeSymbol t)
223222 {
224223 var underlyingType = nts . TypeArguments [ 0 ] ;
225224
226- if ( underlyingType . TypeKind == TypeKind . Enum )
227- {
228- return ToonPrimitiveKind . NullableEnum ;
229- }
230-
231- if ( IsGuid ( underlyingType ) )
225+ if ( underlyingType . TypeKind == TypeKind . Enum || IsGuid ( underlyingType ) || IsTimeSpan ( underlyingType ) || IsDateTimeOffset ( underlyingType ) )
232226 {
233- return ToonPrimitiveKind . NullableGuid ;
227+ return ToonPrimitiveKind . NullableString ;
234228 }
235229
236230 return underlyingType . SpecialType switch
237231 {
238232 SpecialType . System_Boolean => ToonPrimitiveKind . NullableBoolean ,
239- SpecialType . System_DateTime => ToonPrimitiveKind . NullableDateTime ,
233+ SpecialType . System_DateTime => ToonPrimitiveKind . NullableString ,
240234 SpecialType . System_Byte or
241235 SpecialType . System_SByte or
242236 SpecialType . System_Int16 or
@@ -253,20 +247,15 @@ SpecialType.System_Double or
253247 }
254248 else
255249 {
256- if ( t . TypeKind == TypeKind . Enum )
257- {
258- return ToonPrimitiveKind . Enum ;
259- }
260-
261- if ( IsGuid ( t ) )
250+ if ( t . TypeKind == TypeKind . Enum || IsGuid ( t ) || IsTimeSpan ( t ) || IsDateTimeOffset ( t ) )
262251 {
263- return ToonPrimitiveKind . Guid ;
252+ return ToonPrimitiveKind . String ;
264253 }
265254
266255 return t . SpecialType switch
267256 {
268257 SpecialType . System_Boolean => ToonPrimitiveKind . Boolean ,
269- SpecialType . System_DateTime => ToonPrimitiveKind . DateTime ,
258+ SpecialType . System_DateTime => ToonPrimitiveKind . String ,
270259 SpecialType . System_String => ToonPrimitiveKind . String ,
271260 SpecialType . System_Byte or
272261 SpecialType . System_SByte or
@@ -288,6 +277,16 @@ static bool IsGuid(ITypeSymbol type)
288277 {
289278 return type is INamedTypeSymbol { Name : "Guid" , ContainingNamespace : { Name : "System" , ContainingNamespace . IsGlobalNamespace : true } } ;
290279 }
280+
281+ static bool IsTimeSpan ( ITypeSymbol type )
282+ {
283+ return type is INamedTypeSymbol { Name : "TimeSpan" , ContainingNamespace : { Name : "System" , ContainingNamespace . IsGlobalNamespace : true } } ;
284+ }
285+
286+ static bool IsDateTimeOffset ( ITypeSymbol type )
287+ {
288+ return type is INamedTypeSymbol { Name : "DateTimeOffset" , ContainingNamespace : { Name : "System" , ContainingNamespace . IsGlobalNamespace : true } } ;
289+ }
291290 } )
292291 . ToArray ( ) ;
293292
@@ -332,17 +331,11 @@ public bool Verify(SourceProductionContext sourceProductionContext)
332331public enum ToonPrimitiveKind
333332{
334333 Boolean ,
335- String ,
336334 Number ,
337- DateTime , // write as string
338- Guid , // write as string
339- Enum , // write as string
340-
335+ String ,
341336 NullableNumber ,
342337 NullableBoolean ,
343- NullableDateTime ,
344- NullableGuid ,
345- NullableEnum ,
338+ NullableString ,
346339
347340 Unsupported
348341}
0 commit comments