Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/quicktype-core/src/language/CSharp/CSharpRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
} from "../../Type";
import {
directlyReachableSingleNamedType,
matchCompoundType,
matchType,
nullableFromUnion,
removeNullFromUnion,
Expand Down Expand Up @@ -526,4 +527,25 @@ export class CSharpRenderer extends ConvenienceRenderer {

this.emitDefaultFollowingComments();
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ export class NewtonsoftCSharpRenderer extends CSharpRenderer {
}

protected emitUsings(): void {
// FIXME: We need System.Collections.Generic whenever we have maps or use List.
if (!this._needAttributes && !this._needHelpers) return;
if (!this._needAttributes && !this._needHelpers) {
this.emitDependencyUsings();
return;
}

super.emitUsings();
this.ensureBlankLine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ export class SystemTextJsonCSharpRenderer extends CSharpRenderer {
}

protected emitUsings(): void {
// FIXME: We need System.Collections.Generic whenever we have maps or use List.
if (!this._needAttributes && !this._needHelpers) return;
if (!this._needAttributes && !this._needHelpers) {
this.emitDependencyUsings();
return;
}

super.emitUsings();
this.ensureBlankLine();
Expand Down
Loading