@@ -28,6 +28,8 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig
28
28
protected boolean optionalAssemblyInfoFlag = true ;
29
29
protected boolean optionalMethodArgumentFlag = true ;
30
30
protected boolean useDateTimeOffsetFlag = false ;
31
+ protected boolean useCollection = false ;
32
+ protected boolean returnICollection = false ;
31
33
protected String packageTitle = "Swagger Library" ;
32
34
protected String packageProductName = "SwaggerLibrary" ;
33
35
protected String packageDescription = "A library generated from a Swagger doc" ;
@@ -78,6 +80,7 @@ public CSharpClientCodegen() {
78
80
"byte[]" ,
79
81
"ICollection" ,
80
82
"Collection" ,
83
+ "List" ,
81
84
"Dictionary" ,
82
85
"DateTime?" ,
83
86
"DateTimeOffset?" ,
@@ -91,7 +94,8 @@ public CSharpClientCodegen() {
91
94
"Object" )
92
95
);
93
96
94
- instantiationTypes .put ("array" , "Collection" );
97
+ instantiationTypes .put ("array" , "List" );
98
+ instantiationTypes .put ("list" , "List" );
95
99
instantiationTypes .put ("map" , "Dictionary" );
96
100
97
101
typeMapping = new HashMap <String , String >();
@@ -106,8 +110,8 @@ public CSharpClientCodegen() {
106
110
typeMapping .put ("datetime" , "DateTime?" );
107
111
typeMapping .put ("date" , "DateTime?" );
108
112
typeMapping .put ("file" , "Stream" );
109
- typeMapping .put ("array" , "ICollection " );
110
- typeMapping .put ("list" , "ICollection " );
113
+ typeMapping .put ("array" , "List " );
114
+ typeMapping .put ("list" , "List " );
111
115
typeMapping .put ("map" , "Dictionary" );
112
116
typeMapping .put ("object" , "Object" );
113
117
@@ -123,6 +127,11 @@ public CSharpClientCodegen() {
123
127
CodegenConstants .OPTIONAL_ASSEMBLY_INFO_DESC ).defaultValue (Boolean .TRUE .toString ()));
124
128
cliOptions .add (new CliOption (CodegenConstants .SOURCE_FOLDER , CodegenConstants .SOURCE_FOLDER_DESC ).defaultValue (sourceFolder ));
125
129
cliOptions .add (CliOption .newBoolean (CodegenConstants .USE_DATETIME_OFFSET , CodegenConstants .USE_DATETIME_OFFSET_DESC ));
130
+
131
+ cliOptions .add ( CliOption .newBoolean (CodegenConstants .USE_COLLECTION , CodegenConstants .USE_COLLECTION_DESC )
132
+ .defaultValue (Boolean .FALSE .toString ()) );
133
+ cliOptions .add ( CliOption .newBoolean (CodegenConstants .RETURN_ICOLLECTION , CodegenConstants .RETURN_ICOLLECTION_DESC )
134
+ .defaultValue (Boolean .FALSE .toString ()) );
126
135
}
127
136
128
137
@ Override
@@ -179,6 +188,14 @@ public void processOpts() {
179
188
.get (CodegenConstants .OPTIONAL_ASSEMBLY_INFO ).toString ()));
180
189
}
181
190
191
+ if (additionalProperties .containsKey (CodegenConstants .USE_COLLECTION )){
192
+ setUseCollection (Boolean .valueOf (additionalProperties .get (CodegenConstants .USE_COLLECTION ).toString ()));
193
+ }
194
+
195
+ if (additionalProperties .containsKey (CodegenConstants .RETURN_ICOLLECTION )){
196
+ setReturnICollection (Boolean .valueOf (additionalProperties .get (CodegenConstants .RETURN_ICOLLECTION ).toString ()));
197
+ }
198
+
182
199
supportingFiles .add (new SupportingFile ("Configuration.mustache" ,
183
200
sourceFolder + File .separator + clientPackage .replace ("." , java .io .File .separator ), "Configuration.cs" ));
184
201
supportingFiles .add (new SupportingFile ("ApiClient.mustache" ,
@@ -301,13 +318,15 @@ public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
301
318
List <CodegenOperation > ops = (List <CodegenOperation >) operations .get ("operation" );
302
319
for (CodegenOperation operation : ops ) {
303
320
if (operation .returnType != null ) {
304
- // TODO: also change map from Dictionary to IDictionary
305
- if (operation .returnType .startsWith ("ICollection" ) ||
306
- operation .returnType .startsWith ("IDictionary" )) {
307
- // Whenever returnType is an interface, deserialize to the concrete type
308
- operation .returnContainer = operation .returnType .substring (1 );
309
- } else {
310
- operation .returnContainer = operation .returnType ;
321
+ operation .returnContainer = operation .returnType ;
322
+ if ( this .returnICollection && (
323
+ operation .returnType .startsWith ("List" )||
324
+ operation .returnType .startsWith ("Collection" )) ) {
325
+ // NOTE: ICollection works for both List<T> and Collection<T>
326
+ int genericStart = operation .returnType .indexOf ("<" );
327
+ if (genericStart > 0 ) {
328
+ operation .returnType = "ICollection" + operation .returnType .substring (genericStart );
329
+ }
311
330
}
312
331
}
313
332
}
@@ -370,6 +389,21 @@ public void setOptionalMethodArgumentFlag(boolean flag) {
370
389
this .optionalMethodArgumentFlag = flag ;
371
390
}
372
391
392
+ public void setReturnICollection (boolean returnICollection ) {
393
+ this .returnICollection = returnICollection ;
394
+ }
395
+
396
+ public void setUseCollection (boolean useCollection ) {
397
+ this .useCollection = useCollection ;
398
+ if (useCollection ){
399
+ typeMapping .put ("array" , "Collection" );
400
+ typeMapping .put ("list" , "Collection" );
401
+
402
+ instantiationTypes .put ("array" , "Collection" );
403
+ instantiationTypes .put ("list" , "Collection" );
404
+ }
405
+ }
406
+
373
407
public void useDateTimeOffset (boolean flag ) {
374
408
this .useDateTimeOffsetFlag = flag ;
375
409
if (flag )
0 commit comments