Test case
1 generated file · +258 −0test/inputs/regressions/unicode-codepoint-length.schema
Aschema-csharp-SystemTextJsondefault / QuickType.cs+258 −0
| @@ -0,0 +1,258 @@ | ||
| 1 | +// <auto-generated /> | |
| 2 | +// | |
| 3 | +// To parse this JSON data, add NuGet 'System.Text.Json' then do: | |
| 4 | +// | |
| 5 | +// using QuickType; | |
| 6 | +// | |
| 7 | +// var topLevel = TopLevel.FromJson(jsonString); | |
| 8 | +#nullable enable | |
| 9 | +#pragma warning disable CS8618 | |
| 10 | +#pragma warning disable CS8601 | |
| 11 | +#pragma warning disable CS8602 | |
| 12 | +#pragma warning disable CS8603 | |
| 13 | + | |
| 14 | +namespace QuickType | |
| 15 | +{ | |
| 16 | + using System; | |
| 17 | + using System.Collections.Generic; | |
| 18 | + | |
| 19 | + using System.Text.Json; | |
| 20 | + using System.Text.Json.Serialization; | |
| 21 | + using System.Globalization; | |
| 22 | + | |
| 23 | + public partial class TopLevel | |
| 24 | + { | |
| 25 | + [JsonRequired] | |
| 26 | + [JsonPropertyName("exact")] | |
| 27 | + [JsonConverter(typeof(PurpleMinMaxLengthCheckConverter))] | |
| 28 | + public string Exact { get; set; } | |
| 29 | + | |
| 30 | + [JsonRequired] | |
| 31 | + [JsonPropertyName("maximum")] | |
| 32 | + [JsonConverter(typeof(FluffyMinMaxLengthCheckConverter))] | |
| 33 | + public string Maximum { get; set; } | |
| 34 | + | |
| 35 | + [JsonRequired] | |
| 36 | + [JsonPropertyName("minimum")] | |
| 37 | + [JsonConverter(typeof(TentacledMinMaxLengthCheckConverter))] | |
| 38 | + public string Minimum { get; set; } | |
| 39 | + } | |
| 40 | + | |
| 41 | + public partial class TopLevel | |
| 42 | + { | |
| 43 | + public static TopLevel FromJson(string json) => global::System.Text.Json.JsonSerializer.Deserialize<TopLevel>(json, QuickType.Converter.Settings); | |
| 44 | + } | |
| 45 | + | |
| 46 | + public static partial class Serialize | |
| 47 | + { | |
| 48 | + public static string ToJson(this TopLevel self) => JsonSerializer.Serialize(self, QuickType.Converter.Settings); | |
| 49 | + } | |
| 50 | + | |
| 51 | + internal static partial class Converter | |
| 52 | + { | |
| 53 | + public static readonly JsonSerializerOptions Settings = new(JsonSerializerDefaults.General) | |
| 54 | + { | |
| 55 | + Converters = | |
| 56 | + { | |
| 57 | + new DateOnlyConverter(), | |
| 58 | + new TimeOnlyConverter(), | |
| 59 | + IsoDateTimeOffsetConverter.Singleton | |
| 60 | + }, | |
| 61 | + }; | |
| 62 | + } | |
| 63 | + | |
| 64 | + internal class PurpleMinMaxLengthCheckConverter : JsonConverter<string> | |
| 65 | + { | |
| 66 | + public override bool CanConvert(Type t) => t == typeof(string); | |
| 67 | + | |
| 68 | + public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 69 | + { | |
| 70 | + var value = reader.GetString(); | |
| 71 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 2) | |
| 72 | + { | |
| 73 | + return value; | |
| 74 | + } | |
| 75 | + throw new JsonException("Cannot unmarshal type string"); | |
| 76 | + } | |
| 77 | + | |
| 78 | + public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) | |
| 79 | + { | |
| 80 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 2) | |
| 81 | + { | |
| 82 | + JsonSerializer.Serialize(writer, value, options); | |
| 83 | + return; | |
| 84 | + } | |
| 85 | + throw new NotSupportedException("Cannot marshal type string"); | |
| 86 | + } | |
| 87 | + | |
| 88 | + public static readonly PurpleMinMaxLengthCheckConverter Singleton = new PurpleMinMaxLengthCheckConverter(); | |
| 89 | + } | |
| 90 | + | |
| 91 | + internal class FluffyMinMaxLengthCheckConverter : JsonConverter<string> | |
| 92 | + { | |
| 93 | + public override bool CanConvert(Type t) => t == typeof(string); | |
| 94 | + | |
| 95 | + public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 96 | + { | |
| 97 | + var value = reader.GetString(); | |
| 98 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 1) | |
| 99 | + { | |
| 100 | + return value; | |
| 101 | + } | |
| 102 | + throw new JsonException("Cannot unmarshal type string"); | |
| 103 | + } | |
| 104 | + | |
| 105 | + public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) | |
| 106 | + { | |
| 107 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 1) | |
| 108 | + { | |
| 109 | + JsonSerializer.Serialize(writer, value, options); | |
| 110 | + return; | |
| 111 | + } | |
| 112 | + throw new NotSupportedException("Cannot marshal type string"); | |
| 113 | + } | |
| 114 | + | |
| 115 | + public static readonly FluffyMinMaxLengthCheckConverter Singleton = new FluffyMinMaxLengthCheckConverter(); | |
| 116 | + } | |
| 117 | + | |
| 118 | + internal class TentacledMinMaxLengthCheckConverter : JsonConverter<string> | |
| 119 | + { | |
| 120 | + public override bool CanConvert(Type t) => t == typeof(string); | |
| 121 | + | |
| 122 | + public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 123 | + { | |
| 124 | + var value = reader.GetString(); | |
| 125 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2) | |
| 126 | + { | |
| 127 | + return value; | |
| 128 | + } | |
| 129 | + throw new JsonException("Cannot unmarshal type string"); | |
| 130 | + } | |
| 131 | + | |
| 132 | + public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) | |
| 133 | + { | |
| 134 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2) | |
| 135 | + { | |
| 136 | + JsonSerializer.Serialize(writer, value, options); | |
| 137 | + return; | |
| 138 | + } | |
| 139 | + throw new NotSupportedException("Cannot marshal type string"); | |
| 140 | + } | |
| 141 | + | |
| 142 | + public static readonly TentacledMinMaxLengthCheckConverter Singleton = new TentacledMinMaxLengthCheckConverter(); | |
| 143 | + } | |
| 144 | + | |
| 145 | + public class DateOnlyConverter : JsonConverter<DateOnly> | |
| 146 | + { | |
| 147 | + private readonly string serializationFormat; | |
| 148 | + public DateOnlyConverter() : this(null) { } | |
| 149 | + | |
| 150 | + public DateOnlyConverter(string? serializationFormat) | |
| 151 | + { | |
| 152 | + this.serializationFormat = serializationFormat ?? "yyyy-MM-dd"; | |
| 153 | + } | |
| 154 | + | |
| 155 | + public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 156 | + { | |
| 157 | + var value = reader.GetString(); | |
| 158 | + return DateOnly.Parse(value!); | |
| 159 | + } | |
| 160 | + | |
| 161 | + public override void Write(Utf8JsonWriter writer, DateOnly value, JsonSerializerOptions options) | |
| 162 | + => writer.WriteStringValue(value.ToString(serializationFormat)); | |
| 163 | + } | |
| 164 | + | |
| 165 | + public class TimeOnlyConverter : JsonConverter<TimeOnly> | |
| 166 | + { | |
| 167 | + private readonly string serializationFormat; | |
| 168 | + | |
| 169 | + public TimeOnlyConverter() : this(null) { } | |
| 170 | + | |
| 171 | + public TimeOnlyConverter(string? serializationFormat) | |
| 172 | + { | |
| 173 | + this.serializationFormat = serializationFormat ?? "HH:mm:ss.fff"; | |
| 174 | + } | |
| 175 | + | |
| 176 | + public override TimeOnly Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 177 | + { | |
| 178 | + var value = reader.GetString(); | |
| 179 | + return TimeOnly.Parse(value!); | |
| 180 | + } | |
| 181 | + | |
| 182 | + public override void Write(Utf8JsonWriter writer, TimeOnly value, JsonSerializerOptions options) | |
| 183 | + => writer.WriteStringValue(value.ToString(serializationFormat)); | |
| 184 | + } | |
| 185 | + | |
| 186 | + internal class IsoDateTimeOffsetConverter : JsonConverter<DateTimeOffset> | |
| 187 | + { | |
| 188 | + public override bool CanConvert(Type t) => t == typeof(DateTimeOffset); | |
| 189 | + | |
| 190 | + private const string DefaultDateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFFFFFFK"; | |
| 191 | + | |
| 192 | + private DateTimeStyles _dateTimeStyles = DateTimeStyles.RoundtripKind; | |
| 193 | + private string? _dateTimeFormat; | |
| 194 | + private CultureInfo? _culture; | |
| 195 | + | |
| 196 | + public DateTimeStyles DateTimeStyles | |
| 197 | + { | |
| 198 | + get => _dateTimeStyles; | |
| 199 | + set => _dateTimeStyles = value; | |
| 200 | + } | |
| 201 | + | |
| 202 | + public string? DateTimeFormat | |
| 203 | + { | |
| 204 | + get => _dateTimeFormat ?? string.Empty; | |
| 205 | + set => _dateTimeFormat = (string.IsNullOrEmpty(value)) ? null : value; | |
| 206 | + } | |
| 207 | + | |
| 208 | + public CultureInfo Culture | |
| 209 | + { | |
| 210 | + get => _culture ?? CultureInfo.CurrentCulture; | |
| 211 | + set => _culture = value; | |
| 212 | + } | |
| 213 | + | |
| 214 | + public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) | |
| 215 | + { | |
| 216 | + string text; | |
| 217 | + | |
| 218 | + | |
| 219 | + if ((_dateTimeStyles & DateTimeStyles.AdjustToUniversal) == DateTimeStyles.AdjustToUniversal | |
| 220 | + || (_dateTimeStyles & DateTimeStyles.AssumeUniversal) == DateTimeStyles.AssumeUniversal) | |
| 221 | + { | |
| 222 | + value = value.ToUniversalTime(); | |
| 223 | + } | |
| 224 | + | |
| 225 | + text = value.ToString(_dateTimeFormat ?? DefaultDateTimeFormat, Culture); | |
| 226 | + | |
| 227 | + writer.WriteStringValue(text); | |
| 228 | + } | |
| 229 | + | |
| 230 | + public override DateTimeOffset Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | |
| 231 | + { | |
| 232 | + string? dateText = reader.GetString(); | |
| 233 | + | |
| 234 | + if (string.IsNullOrEmpty(dateText) == false) | |
| 235 | + { | |
| 236 | + if (!string.IsNullOrEmpty(_dateTimeFormat)) | |
| 237 | + { | |
| 238 | + return DateTimeOffset.ParseExact(dateText, _dateTimeFormat, Culture, _dateTimeStyles); | |
| 239 | + } | |
| 240 | + else | |
| 241 | + { | |
| 242 | + return DateTimeOffset.Parse(dateText, Culture, _dateTimeStyles); | |
| 243 | + } | |
| 244 | + } | |
| 245 | + else | |
| 246 | + { | |
| 247 | + return default(DateTimeOffset); | |
| 248 | + } | |
| 249 | + } | |
| 250 | + | |
| 251 | + | |
| 252 | + public static readonly IsoDateTimeOffsetConverter Singleton = new IsoDateTimeOffsetConverter(); | |
| 253 | + } | |
| 254 | +} | |
| 255 | +#pragma warning restore CS8618 | |
| 256 | +#pragma warning restore CS8601 | |
| 257 | +#pragma warning restore CS8602 | |
| 258 | +#pragma warning restore CS8603 |
Test case
1 generated file · +12 −12test/inputs/schema/minmaxlength.schema
Mschema-csharp-SystemTextJsondefault / QuickType.cs+12 −12
| @@ -107,7 +107,7 @@ namespace QuickType | ||
| 107 | 107 | return new InUnion { Double = doubleValue1 }; |
| 108 | 108 | case JsonTokenType.String: |
| 109 | 109 | var stringValue = reader.GetString(); |
| 110 | - if (stringValue.Length >= 3 && stringValue.Length <= 5) | |
| 110 | + if (System.Linq.Enumerable.Count(stringValue!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(stringValue!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 111 | 111 | { |
| 112 | 112 | return new InUnion { String = stringValue }; |
| 113 | 113 | } |
| @@ -125,7 +125,7 @@ namespace QuickType | ||
| 125 | 125 | } |
| 126 | 126 | if (value.String != null) |
| 127 | 127 | { |
| 128 | - if (value.String.Length >= 3 && value.String.Length <= 5) | |
| 128 | + if (System.Linq.Enumerable.Count(value.String!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value.String!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 129 | 129 | { |
| 130 | 130 | JsonSerializer.Serialize(writer, value.String, options); |
| 131 | 131 | return; |
| @@ -144,7 +144,7 @@ namespace QuickType | ||
| 144 | 144 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 145 | 145 | { |
| 146 | 146 | var value = reader.GetString(); |
| 147 | - if (value.Length >= 3 && value.Length <= 5) | |
| 147 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 148 | 148 | { |
| 149 | 149 | return value; |
| 150 | 150 | } |
| @@ -153,7 +153,7 @@ namespace QuickType | ||
| 153 | 153 | |
| 154 | 154 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 155 | 155 | { |
| 156 | - if (value.Length >= 3 && value.Length <= 5) | |
| 156 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 157 | 157 | { |
| 158 | 158 | JsonSerializer.Serialize(writer, value, options); |
| 159 | 159 | return; |
| @@ -171,7 +171,7 @@ namespace QuickType | ||
| 171 | 171 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 172 | 172 | { |
| 173 | 173 | var value = reader.GetString(); |
| 174 | - if (value.Length >= 4 && value.Length <= 5) | |
| 174 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 4 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 175 | 175 | { |
| 176 | 176 | return value; |
| 177 | 177 | } |
| @@ -180,7 +180,7 @@ namespace QuickType | ||
| 180 | 180 | |
| 181 | 181 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 182 | 182 | { |
| 183 | - if (value.Length >= 4 && value.Length <= 5) | |
| 183 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 4 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 184 | 184 | { |
| 185 | 185 | JsonSerializer.Serialize(writer, value, options); |
| 186 | 186 | return; |
| @@ -198,7 +198,7 @@ namespace QuickType | ||
| 198 | 198 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 199 | 199 | { |
| 200 | 200 | var value = reader.GetString(); |
| 201 | - if (value.Length <= 5) | |
| 201 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 202 | 202 | { |
| 203 | 203 | return value; |
| 204 | 204 | } |
| @@ -207,7 +207,7 @@ namespace QuickType | ||
| 207 | 207 | |
| 208 | 208 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 209 | 209 | { |
| 210 | - if (value.Length <= 5) | |
| 210 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 211 | 211 | { |
| 212 | 212 | JsonSerializer.Serialize(writer, value, options); |
| 213 | 213 | return; |
| @@ -225,7 +225,7 @@ namespace QuickType | ||
| 225 | 225 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 226 | 226 | { |
| 227 | 227 | var value = reader.GetString(); |
| 228 | - if (value.Length >= 3) | |
| 228 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3) | |
| 229 | 229 | { |
| 230 | 230 | return value; |
| 231 | 231 | } |
| @@ -234,7 +234,7 @@ namespace QuickType | ||
| 234 | 234 | |
| 235 | 235 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 236 | 236 | { |
| 237 | - if (value.Length >= 3) | |
| 237 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3) | |
| 238 | 238 | { |
| 239 | 239 | JsonSerializer.Serialize(writer, value, options); |
| 240 | 240 | return; |
| @@ -252,7 +252,7 @@ namespace QuickType | ||
| 252 | 252 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 253 | 253 | { |
| 254 | 254 | var value = reader.GetString(); |
| 255 | - if (value.Length >= 3 && value.Length <= 6) | |
| 255 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 6) | |
| 256 | 256 | { |
| 257 | 257 | return value; |
| 258 | 258 | } |
| @@ -261,7 +261,7 @@ namespace QuickType | ||
| 261 | 261 | |
| 262 | 262 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 263 | 263 | { |
| 264 | - if (value.Length >= 3 && value.Length <= 6) | |
| 264 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 6) | |
| 265 | 265 | { |
| 266 | 266 | JsonSerializer.Serialize(writer, value, options); |
| 267 | 267 | return; |
Test case
1 generated file · +2 −2test/inputs/schema/optional-const-ref.schema
Mschema-csharp-SystemTextJsondefault / QuickType.cs+2 −2
| @@ -124,7 +124,7 @@ namespace QuickType | ||
| 124 | 124 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 125 | 125 | { |
| 126 | 126 | var value = reader.GetString(); |
| 127 | - if (value.Length >= 2 && value.Length <= 16) | |
| 127 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 16) | |
| 128 | 128 | { |
| 129 | 129 | return value; |
| 130 | 130 | } |
| @@ -133,7 +133,7 @@ namespace QuickType | ||
| 133 | 133 | |
| 134 | 134 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 135 | 135 | { |
| 136 | - if (value.Length >= 2 && value.Length <= 16) | |
| 136 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 2 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 16) | |
| 137 | 137 | { |
| 138 | 138 | JsonSerializer.Serialize(writer, value, options); |
| 139 | 139 | return; |
Test case
1 generated file · +2 −2test/inputs/schema/optional-constraints.schema
Mschema-csharp-SystemTextJsondefault / QuickType.cs+2 −2
| @@ -131,7 +131,7 @@ namespace QuickType | ||
| 131 | 131 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 132 | 132 | { |
| 133 | 133 | var value = reader.GetString(); |
| 134 | - if (value.Length >= 3 && value.Length <= 10) | |
| 134 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 10) | |
| 135 | 135 | { |
| 136 | 136 | return value; |
| 137 | 137 | } |
| @@ -140,7 +140,7 @@ namespace QuickType | ||
| 140 | 140 | |
| 141 | 141 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 142 | 142 | { |
| 143 | - if (value.Length >= 3 && value.Length <= 10) | |
| 143 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 3 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 10) | |
| 144 | 144 | { |
| 145 | 145 | JsonSerializer.Serialize(writer, value, options); |
| 146 | 146 | return; |
Test case
1 generated file · +2 −2test/inputs/schema/renaming-bug.schema
Mschema-csharp-SystemTextJsondefault / QuickType.cs+2 −2
| @@ -228,7 +228,7 @@ namespace QuickType | ||
| 228 | 228 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 229 | 229 | { |
| 230 | 230 | var value = reader.GetString(); |
| 231 | - if (value.Length >= 1) | |
| 231 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 1) | |
| 232 | 232 | { |
| 233 | 233 | return value; |
| 234 | 234 | } |
| @@ -237,7 +237,7 @@ namespace QuickType | ||
| 237 | 237 | |
| 238 | 238 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 239 | 239 | { |
| 240 | - if (value.Length >= 1) | |
| 240 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 1) | |
| 241 | 241 | { |
| 242 | 242 | JsonSerializer.Serialize(writer, value, options); |
| 243 | 243 | return; |
Test case
1 generated file · +2 −2test/inputs/schema/schema-constraints.schema
Mschema-csharp-SystemTextJsondefault / QuickType.cs+2 −2
| @@ -63,7 +63,7 @@ namespace QuickType | ||
| 63 | 63 | public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) |
| 64 | 64 | { |
| 65 | 65 | var value = reader.GetString(); |
| 66 | - if (value.Length >= 5 && value.Length <= 5) | |
| 66 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 5 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 67 | 67 | { |
| 68 | 68 | return value; |
| 69 | 69 | } |
| @@ -72,7 +72,7 @@ namespace QuickType | ||
| 72 | 72 | |
| 73 | 73 | public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) |
| 74 | 74 | { |
| 75 | - if (value.Length >= 5 && value.Length <= 5) | |
| 75 | + if (System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) >= 5 && System.Linq.Enumerable.Count(value!, c => !char.IsLowSurrogate(c)) <= 5) | |
| 76 | 76 | { |
| 77 | 77 | JsonSerializer.Serialize(writer, value, options); |
| 78 | 78 | return; |
No generated files match these filters.