@@ -78,7 +78,7 @@ function needTransformerForType(t: Type): "automatic" | "manual" | "nullable" |
78
78
return "none" ;
79
79
}
80
80
if ( t instanceof EnumType ) return "automatic" ;
81
- if ( t . kind === "integer-string" ) return "manual" ;
81
+ if ( t . kind === "integer-string" || t . kind === "bool-string" ) return "manual" ;
82
82
return "none" ;
83
83
}
84
84
@@ -91,7 +91,7 @@ function alwaysApplyTransformation(xf: Transformation): boolean {
91
91
92
92
/**
93
93
* The C# type for a given transformed string type. The function can
94
- * assume that it will only be called for type kinds that
94
+ * assume that it will only be called for type kinds that
95
95
*/
96
96
function csTypeForTransformedStringType ( t : PrimitiveType ) : Sourcelike {
97
97
if ( t . kind === "date-time" ) {
@@ -140,6 +140,7 @@ export class CSharpTargetLanguage extends TargetLanguage {
140
140
mapping . set ( "time" , "date-time" ) ;
141
141
mapping . set ( "date-time" , "date-time" ) ;
142
142
mapping . set ( "integer-string" , "integer-string" ) ;
143
+ mapping . set ( "bool-string" , "bool-string" ) ;
143
144
return mapping ;
144
145
}
145
146
@@ -1144,6 +1145,11 @@ export class NewtonsoftCSharpRenderer extends CSharpRenderer {
1144
1145
this . emitLine ( "if (Int64.TryParse(" , variable , ", out l))" ) ;
1145
1146
this . emitBlock ( ( ) => this . emitConsume ( "l" , xfer . consumer , targetType , emitFinish ) ) ;
1146
1147
break ;
1148
+ case "bool" :
1149
+ this . emitLine ( "bool b;" ) ;
1150
+ this . emitLine ( "if (Boolean.TryParse(" , variable , ", out b))" ) ;
1151
+ this . emitBlock ( ( ) => this . emitConsume ( "b" , xfer . consumer , targetType , emitFinish ) ) ;
1152
+ break ;
1147
1153
default :
1148
1154
return panic ( `Parsing string to ${ immediateTargetType . kind } not supported` ) ;
1149
1155
}
@@ -1158,6 +1164,9 @@ export class NewtonsoftCSharpRenderer extends CSharpRenderer {
1158
1164
) ;
1159
1165
case "integer" :
1160
1166
return this . emitConsume ( [ variable , ".ToString()" ] , xfer . consumer , targetType , emitFinish ) ;
1167
+ case "bool" :
1168
+ this . emitLine ( "var boolString = " , variable , ' ? "true" : "false";' ) ;
1169
+ return this . emitConsume ( "boolString" , xfer . consumer , targetType , emitFinish ) ;
1161
1170
default :
1162
1171
return panic ( `Stringifying ${ xfer . sourceType . kind } not supported` ) ;
1163
1172
}
0 commit comments