MCPcopy Create free account
hub / github.com/glideapps/quicktype / CSharpRenderer

Class CSharpRenderer

src/Language/CSharp.ts:113–620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113class CSharpRenderer extends ConvenienceRenderer {
114 private _enumExtensionsNames = Map<Name, Name>();
115 private readonly _needHelpers: boolean;
116 private readonly _needAttributes: boolean;
117
118 constructor(
119 graph: TypeGraph,
120 private readonly _namespaceName: string,
121 private readonly _version: Version,
122 private readonly _dense: boolean,
123 private readonly _useList: boolean,
124 outputFeatures: OutputFeatures
125 ) {
126 super(graph);
127 this._needHelpers = outputFeatures.helpers;
128 this._needAttributes = outputFeatures.attributes;
129 }
130
131 protected get forbiddenNamesForGlobalNamespace(): string[] {
132 return ["QuickType", "Converter", "JsonConverter", "Type", "Serialize"];
133 }
134
135 protected forbiddenForClassProperties(_: ClassType, classNamed: Name): { names: Name[]; namespaces: Namespace[] } {
136 return { names: [classNamed], namespaces: [] };
137 }
138
139 protected topLevelNameStyle(rawName: string): string {
140 return csNameStyle(rawName);
141 }
142
143 protected get namedTypeNamer(): Namer {
144 return namingFunction;
145 }
146
147 protected get classPropertyNamer(): Namer {
148 return namingFunction;
149 }
150
151 protected get unionMemberNamer(): Namer {
152 return namingFunction;
153 }
154
155 protected get enumCaseNamer(): Namer {
156 return namingFunction;
157 }
158
159 protected unionNeedsName(u: UnionType): boolean {
160 return !nullableFromUnion(u);
161 }
162
163 protected namedTypeToNameForTopLevel(type: Type): NamedType | null {
164 const definedTypes = type.directlyReachableTypes(t => {
165 if ((!(t instanceof UnionType) && t.isNamedType()) || (t instanceof UnionType && !nullableFromUnion(t))) {
166 return OrderedSet([t]);
167 }
168 return null;
169 });
170 assert(definedTypes.size <= 1, "Cannot have more than one defined type per top-level");

Callers

nothing calls this directly

Calls 11

emitExpressionMemberMethod · 0.95
emitTypeSwitchMethod · 0.95
matchTypeFunction · 0.90
maybeAnnotatedFunction · 0.90
nullableFromUnionFunction · 0.90
definedFunction · 0.90
removeNullFromUnionFunction · 0.90
intercalateFunction · 0.90
isValueTypeFunction · 0.70
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…