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
Original file line number Diff line number Diff line change
Expand Up @@ -1141,16 +1141,21 @@ export class SystemTextJsonCSharpRenderer extends CSharpRenderer {
emitFinish,
);
} else if (xfer instanceof MinMaxLengthCheckTransformer) {
const length = [
"System.Linq.Enumerable.Count(",
variable,
"!, c => !char.IsLowSurrogate(c))",
];
const min = xfer.minLength;
const max = xfer.maxLength;
const conditions: Sourcelike[] = [];

if (min !== undefined) {
conditions.push([variable, ".Length >= ", min.toString()]);
conditions.push([length, " >= ", min.toString()]);
}

if (max !== undefined) {
conditions.push([variable, ".Length <= ", max.toString()]);
conditions.push([length, " <= ", max.toString()]);
}

this.emitLine("if (", arrayIntercalate([" && "], conditions), ")");
Expand Down
4 changes: 4 additions & 0 deletions test/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,16 @@ export const CSharpLanguageSystemTextJson: Language = {
"uuid",
"minmax",
"minmaxInteger",
"minmaxlength",
"integer",
],
output: "QuickType.cs",
topLevel: "TopLevel",
skipJSON: [],
skipMiscJSON: false,
additionalSchemaFiles: [
"test/inputs/regressions/unicode-codepoint-length.schema",
],
skipSchema: [
// The following skips are pre-existing System.Text.Json renderer issues,
// found when first enabling the schema fixture for this language:
Expand Down
Loading