@@ -97,6 +97,9 @@ function csTypeForTransformedStringType(t: PrimitiveType): Sourcelike {
97
97
if ( t . kind === "date-time" ) {
98
98
return "DateTimeOffset" ;
99
99
}
100
+ if ( t . kind === "uuid" ) {
101
+ return "Guid" ;
102
+ }
100
103
return panic ( `Transformed string type ${ t . kind } not supported` ) ;
101
104
}
102
105
@@ -139,6 +142,7 @@ export class CSharpTargetLanguage extends TargetLanguage {
139
142
mapping . set ( "date" , "date-time" ) ;
140
143
mapping . set ( "time" , "date-time" ) ;
141
144
mapping . set ( "date-time" , "date-time" ) ;
145
+ mapping . set ( "uuid" , "uuid" ) ;
142
146
mapping . set ( "integer-string" , "integer-string" ) ;
143
147
mapping . set ( "bool-string" , "bool-string" ) ;
144
148
return mapping ;
@@ -204,7 +208,7 @@ function isValueType(t: Type): boolean {
204
208
if ( t instanceof UnionType ) {
205
209
return nullableFromUnion ( t ) === null ;
206
210
}
207
- return [ "integer" , "double" , "bool" , "enum" , "date-time" ] . indexOf ( t . kind ) >= 0 ;
211
+ return [ "integer" , "double" , "bool" , "enum" , "date-time" , "uuid" ] . indexOf ( t . kind ) >= 0 ;
208
212
}
209
213
210
214
export class CSharpRenderer extends ConvenienceRenderer {
@@ -217,7 +221,7 @@ export class CSharpRenderer extends ConvenienceRenderer {
217
221
}
218
222
219
223
protected forbiddenNamesForGlobalNamespace ( ) : string [ ] {
220
- return [ "QuickType" , "Type" , "System" , "Console" , "Exception" , "DateTimeOffset" ] ;
224
+ return [ "QuickType" , "Type" , "System" , "Console" , "Exception" , "DateTimeOffset" , "Guid" ] ;
221
225
}
222
226
223
227
protected forbiddenForObjectProperties ( _ : ClassType , classNamed : Name ) : ForbiddenWordsInfo {
@@ -1140,6 +1144,11 @@ export class NewtonsoftCSharpRenderer extends CSharpRenderer {
1140
1144
this . emitLine ( "if (DateTimeOffset.TryParse(" , variable , ", out dt))" ) ;
1141
1145
this . emitBlock ( ( ) => this . emitConsume ( "dt" , xfer . consumer , targetType , emitFinish ) ) ;
1142
1146
break ;
1147
+ case "uuid" :
1148
+ this . emitLine ( "Guid guid;" ) ;
1149
+ this . emitLine ( "if (Guid.TryParse(" , variable , ", out guid))" ) ;
1150
+ this . emitBlock ( ( ) => this . emitConsume ( "guid" , xfer . consumer , targetType , emitFinish ) ) ;
1151
+ break ;
1143
1152
case "integer" :
1144
1153
this . emitLine ( "long l;" ) ;
1145
1154
this . emitLine ( "if (Int64.TryParse(" , variable , ", out l))" ) ;
@@ -1162,6 +1171,13 @@ export class NewtonsoftCSharpRenderer extends CSharpRenderer {
1162
1171
targetType ,
1163
1172
emitFinish
1164
1173
) ;
1174
+ case "uuid" :
1175
+ return this . emitConsume (
1176
+ [ variable , '.ToString("D", System.Globalization.CultureInfo.InvariantCulture)' ] ,
1177
+ xfer . consumer ,
1178
+ targetType ,
1179
+ emitFinish
1180
+ ) ;
1165
1181
case "integer" :
1166
1182
return this . emitConsume ( [ variable , ".ToString()" ] , xfer . consumer , targetType , emitFinish ) ;
1167
1183
case "bool" :
0 commit comments