MCPcopy Index your code
hub / github.com/github/copilot-sdk / getJsonUnionMatchExpression

Function getJsonUnionMatchExpression

scripts/codegen/csharp.ts:940–968  ·  view source on GitHub ↗
(variant: JsonUnionVariant, variants: JsonUnionVariant[])

Source from the content-addressed store, hash-verified

938}
939
940function getJsonUnionMatchExpression(variant: JsonUnionVariant, variants: JsonUnionVariant[]): string | undefined {
941 const required = new Set(variant.schema?.required ?? []);
942 if (required.size === 0) return undefined;
943
944 const otherRequired = new Set<string>();
945 for (const other of variants) {
946 if (other === variant) continue;
947 for (const property of other.schema?.required ?? []) {
948 otherRequired.add(property);
949 }
950 }
951
952 const present = [...required].filter((property) => !otherRequired.has(property));
953 if (present.length === 0) return undefined;
954
955 const absent = new Set<string>();
956 for (const other of variants) {
957 if (other === variant) continue;
958 for (const property of other.schema?.required ?? []) {
959 if (!required.has(property)) absent.add(property);
960 }
961 }
962
963 return [
964 "element.ValueKind == JsonValueKind.Object",
965 ...present.map((property) => `element.TryGetProperty("${escapeCSharpStringLiteral(property)}", out _)`),
966 ...[...absent].sort().map((property) => `!element.TryGetProperty("${escapeCSharpStringLiteral(property)}", out _)`),
967 ].join(" && ");
968}
969
970function generateJsonUnionClass(className: string, variants: JsonUnionVariant[], description: string | undefined, jsonContextType: string, isInternal: boolean): string {
971 const lines: string[] = [];

Callers 1

generateJsonUnionClassFunction · 0.85

Calls 3

joinMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…