Skip to content

Commit

Permalink
PR change : removed array usage for emiting , added local function to…
Browse files Browse the repository at this point in the history
… ensure single addition of "System.Collections.Generic"
  • Loading branch information
sakets594 committed Jun 8, 2024
1 parent 9c7467c commit 0f67311
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/quicktype-core/src/language/CSharp/CSharpRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,23 @@ export class CSharpRenderer extends ConvenienceRenderer {
}

protected emitDependencyUsings(): void {
let nameSpaceForTypes: string[] = [];
let genericEmited: boolean = false;
let ensureGenericOnce = () => {
if (!genericEmited) {
this.emitUsing("System.Collections.Generic");
genericEmited = true;
}
}
this.typeGraph.allTypesUnordered().forEach(_ => {
matchCompoundType(
_,
_arrayType => this._csOptions.useList ? nameSpaceForTypes.push("System.Collections.Generic") : undefined,
_arrayType => this._csOptions.useList ? ensureGenericOnce() : undefined,
_classType => { },
_mapType => nameSpaceForTypes.push("System.Collections.Generic"),
_mapType => ensureGenericOnce(),
_objectType => { },
_unionType => { }
)
});
nameSpaceForTypes = nameSpaceForTypes.filter((val, ind) => nameSpaceForTypes.indexOf(val) === ind );
nameSpaceForTypes.forEach(this.emitUsing.bind(this));
}

}

0 comments on commit 0f67311

Please sign in to comment.