Skip to content

Commit 0f67311

Browse files
committed
PR change : removed array usage for emiting , added local function to ensure single addition of "System.Collections.Generic"
1 parent 9c7467c commit 0f67311

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/quicktype-core/src/language/CSharp/CSharpRenderer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,23 @@ export class CSharpRenderer extends ConvenienceRenderer {
389389
}
390390

391391
protected emitDependencyUsings(): void {
392-
let nameSpaceForTypes: string[] = [];
392+
let genericEmited: boolean = false;
393+
let ensureGenericOnce = () => {
394+
if (!genericEmited) {
395+
this.emitUsing("System.Collections.Generic");
396+
genericEmited = true;
397+
}
398+
}
393399
this.typeGraph.allTypesUnordered().forEach(_ => {
394400
matchCompoundType(
395401
_,
396-
_arrayType => this._csOptions.useList ? nameSpaceForTypes.push("System.Collections.Generic") : undefined,
402+
_arrayType => this._csOptions.useList ? ensureGenericOnce() : undefined,
397403
_classType => { },
398-
_mapType => nameSpaceForTypes.push("System.Collections.Generic"),
404+
_mapType => ensureGenericOnce(),
399405
_objectType => { },
400406
_unionType => { }
401407
)
402408
});
403-
nameSpaceForTypes = nameSpaceForTypes.filter((val, ind) => nameSpaceForTypes.indexOf(val) === ind );
404-
nameSpaceForTypes.forEach(this.emitUsing.bind(this));
405409
}
406410

407411
}

0 commit comments

Comments
 (0)