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

Method namedTypeToNameForTopLevel

src/Language/CSharp.ts:163–179  ·  view source on GitHub ↗
(type: Type)

Source from the content-addressed store, hash-verified

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");
171
172 // If the top-level type doesn't contain any classes or unions
173 // we have to define a class just for the `FromJson` method, in
174 // emitFromJsonForTopLevel.
175
176 const first = definedTypes.first();
177 if (first === undefined) return null;
178 return first;
179 }
180
181 protected namedTypeDependencyNames(t: NamedType, name: Name): DependencyName[] {
182 if (!(t instanceof EnumType)) return [];

Callers 1

CSharpRendererClass · 0.95

Calls 2

nullableFromUnionFunction · 0.90
assertFunction · 0.90

Tested by

no test coverage detected